View source

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Cache\Cache;

 * Implements hook_form_FORM_ID_alter()
 * Add visualn_block specific iframes configuration settings.
 * Use 'visualn_iframe_configuration' form_id.
 * @see \Drupal\visualn_iframe\Form::ConfigurationForm
 * @ingroup iframes_toolkit
function visualn_block_form_visualn_iframe_configuration_alter(&$form, FormStateInterface $form_state, $form_id) {
  $config = \Drupal::config('visualn_block.iframe.settings');
  $form['visualn_block'] = [
    '#type' => 'details',
    '#title' => 'VisualN Block',
    '#open' => FALSE,
  $form['visualn_block']['allow_blocks_sharing'] = [
    '#type' => 'checkbox',
    '#title' => t('Allow Blocks sharing'),
    '#default_value' => $config
    '#description' => t('Allow sharing for VisualN blocks'),

  // @todo: add a setting to hide/show exposed share links that wouldn't depend on the setting above
  $form['visualn_block']['implicit_entries_restore'] = [
    '#type' => 'checkbox',
    '#title' => t('Enable missing iframe entries implicit restore'),
    '#default_value' => $config
    '#description' => t('Recreate VisualN block drawings on block view if an iframe entry doesn\'t exist. Useful when importing blocks config on other sites. <strong>Should be used only when needed and commonly disabled</strong>.'),

  // @todo: maybe use array_unshift to execute it first and remove its values
  $form['#submit'][] = 'visualn_block_iframe_configuration_form_submit';

 * Submit visualn_block iframe settings values (visualn_iframe settings subform).
function visualn_block_iframe_configuration_form_submit($form, FormStateInterface $form_state) {
  $config = \Drupal::service('config.factory')
  $values = $form_state

  // @todo: maybe use setData() instead to override whole config
  //   though don't override 'dependencies' key
  foreach ($values as $key => $value) {
      ->set($key, $value);

  // The cache tag attached in VisualNBlock::build() to blocks
  // drawings share links to reset the cache and show/hide links
  // on allow_drawings_sharing setting change.
  // @todo: maybe also use more specific cache tags,
  //   e.g. visualn_block_iframe_settings:setting_name
  //   or visualn_block:iframe_settings:setting_name
  //   or visualn_block.iframe_settings:setting_name (to avoid possible name collissions)
  $tags = [


Namesort descending Description
visualn_block_form_visualn_iframe_configuration_alter Implements hook_form_FORM_ID_alter()
visualn_block_iframe_configuration_form_submit Submit visualn_block iframe settings values (visualn_iframe settings subform).