defaultConfiguration example

/** * {@inheritdoc} */
  public function getConfiguration() {
    return $this->configuration;
  }

  /** * {@inheritdoc} */
  public function setConfiguration(array $configuration) {
    $this->configuration = NestedArray::mergeDeep($this->defaultConfiguration()$configuration);
  }

  /** * {@inheritdoc} */
  public function defaultConfiguration() {
    return [
      'label' => '',
    ];
  }

  
/** * {@inheritdoc} */
  public function defaultConfiguration() {
    return [
      'view' => [
        'view_name' => NULL,
        'display_name' => NULL,
        'arguments' => [],
      ],
    ] + parent::defaultConfiguration();
  }

  /** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form$form_state);

    $view_settings = $this->getConfiguration()['view'];
    $displays = Views::getApplicableViews('entity_reference_display');
    // Filter views that list the entity type we want, and group the separate
/** * {@inheritdoc} */
  public function getConfiguration() {
    return $this->configuration;
  }

  /** * {@inheritdoc} */
  public function setConfiguration(array $configuration) {
    $this->configuration = $configuration + $this->defaultConfiguration();
  }

}
return [
      // For the 'target_bundles' setting, a NULL value is equivalent to "allow       // entities from any bundle to be referenced" and an empty array value is       // equivalent to "no entities from any bundle can be referenced".       'target_bundles' => NULL,
      'sort' => [
        'field' => '_none',
        'direction' => 'ASC',
      ],
      'auto_create' => FALSE,
      'auto_create_bundle' => NULL,
    ] + parent::defaultConfiguration();
  }

  /** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form$form_state);

    $configuration = $this->getConfiguration();
    $entity_type_id = $configuration['target_type'];
    $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
    
return $build;
    }

    return $build + $tabs;
  }

  /** * {@inheritdoc} */
  public function blockForm($form, FormStateInterface $form_state) {
    $config = $this->configuration;
    $defaults = $this->defaultConfiguration();

    $form['levels'] = [
      '#type' => 'details',
      '#title' => $this->t('Shown tabs'),
      '#description' => $this->t('Select tabs being shown in the block'),
      // Open if not set to defaults.       '#open' => $defaults['primary'] !== $config['primary'] || $defaults['secondary'] !== $config['secondary'],
    ];
    $form['levels']['primary'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Show primary tabs'),
      
$plugin_id,
      $plugin_definition,
      $container->get('theme.manager'),
      $container->get('theme_handler')
    );
  }

  /** * {@inheritdoc} */
  public function defaultConfiguration() {
    return ['theme' => ''] + parent::defaultConfiguration();
  }

  /** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['theme'] = [
      '#type' => 'select',
      '#title' => $this->t('Theme'),
      '#default_value' => $this->configuration['theme'],
      '#options' => array_map(function D$theme_info) {
        


    if (isset($definition['drupal']['class']) && !class_exists($definition['drupal']['class'])) {
      throw new InvalidPluginDefinitionException($idsprintf('The CKEditor 5 "%s" provides a plugin class: "%s", but it does not exist.', $id$definition['drupal']['class']));
    }
    elseif (isset($definition['drupal']['class']) && !in_array(CKEditor5PluginInterface::classclass_implements($definition['drupal']['class']))) {
      throw new InvalidPluginDefinitionException($idsprintf('CKEditor 5 plugins must implement \Drupal\ckeditor5\Plugin\CKEditor5PluginInterface. "%s" does not.', $id));
    }
    elseif (in_array(CKEditor5PluginConfigurableInterface::classclass_implements($definition['drupal']['class'], TRUE))) {
      $default_configuration = (new \ReflectionClass($definition['drupal']['class']))
        ->newInstanceWithoutConstructor()
        ->defaultConfiguration();
      if (!empty($default_configuration)) {
        $configuration_name = sprintf("ckeditor5.plugin.%s", $definition['id']);
        if (!$this->getTypedConfig()->hasConfigSchema($configuration_name)) {
          throw new InvalidPluginDefinitionException($idsprintf('The "%s" CKEditor 5 plugin definition is configurable, has non-empty default configuration but has no config schema. Config schema is required for validation.', $id));
        }
        $error_message = $this->validateConfiguration($default_configuration);
        if ($error_message) {
          throw new InvalidPluginDefinitionException($idsprintf('The "%s" CKEditor 5 plugin definition is configurable, but its default configuration does not match its config schema. %s', $id$error_message));
        }
      }
    }

    

abstract class MultiWidthLayoutBase extends LayoutDefault implements PluginFormInterface {

  /** * {@inheritdoc} */
  public function defaultConfiguration() {
    $configuration = parent::defaultConfiguration();
    return $configuration + [
      'column_widths' => $this->getDefaultWidth(),
    ];
  }

  /** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['column_widths'] = [
      '#type' => 'select',
      

  public function onDependencyRemoval(array $dependencies) {
    // Always return TRUE to allow the logic in     // \Drupal\workflows\Entity\Workflow::onDependencyRemoval() to be tested.     return TRUE;
  }

  /** * {@inheritdoc} */
  public function defaultConfiguration() {
    return parent::defaultConfiguration() + [
      'example_setting' => '',
    ];
  }

}
public function getConfiguration() {
    $configuration = parent::getConfiguration();
    // Remove configuration if it matches the defaults. In self::getAll(), we     // load all available filters, in addition to the enabled filters stored in     // configuration. In order to prevent those from bleeding through to the     // stored configuration, remove all filters that match the default values.     // Because filters are disabled by default, this will never remove the     // configuration of an enabled filter.     foreach ($configuration as $instance_id => $instance_config) {
      $default_config = [];
      $default_config['id'] = $instance_id;
      $default_config += $this->get($instance_id)->defaultConfiguration();
      if ($default_config === $instance_config) {
        unset($configuration[$instance_id]);
      }
    }
    return $configuration;
  }

}
'#data' => $this->configuration,
    ];
    $summary += parent::getSummary();

    return $summary;
  }

  /** * {@inheritdoc} */
  public function defaultConfiguration() {
    return parent::defaultConfiguration() + [
      'anchor' => 'center-center',
    ];
  }

  /** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form$form_state);
    $form['anchor'] = [
      '#type' => 'radios',
      


  /** * {@inheritdoc} */
  public function setConfiguration(array $configuration) {
    $configuration += [
      'data' => [],
      'uuid' => '',
      'weight' => '',
    ];
    $this->configuration = $configuration['data'] + $this->defaultConfiguration();
    $this->uuid = $configuration['uuid'];
    $this->weight = $configuration['weight'];
    return $this;
  }

  /** * {@inheritdoc} */
  public function defaultConfiguration() {
    return [];
  }

  

  public function getConfiguration() {
    return $this->configuration;
  }

  /** * {@inheritdoc} */
  public function setConfiguration(array $configuration) {
    // Merge in defaults.     $this->configuration = NestedArray::mergeDeep(
      $this->defaultConfiguration(),
      $configuration
    );
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    return [];
  }

  
$this->defaultPluginCollection->addInstanceId('banana', ['id' => 'banana', 'key' => 'other_value']);
    $this->assertEquals(['banana' => 'banana']$this->defaultPluginCollection->getInstanceIds());
  }

}

class ConfigurablePlugin extends PluginBase implements ConfigurableInterface {

  public function __construct(array $configuration$plugin_id$plugin_definition) {
    parent::__construct($configuration$plugin_id$plugin_definition);

    $this->configuration = $configuration + $this->defaultConfiguration();
  }

  public function defaultConfiguration() {
    return [];
  }

  public function getConfiguration() {
    return $this->configuration;
  }

  public function setConfiguration(array $configuration) {
    
'@bundle' => $bundle,
      ]);
    }
  }

  /** * {@inheritdoc} */
  public function defaultConfiguration() {
    return [
      'bundles' => [],
    ] + parent::defaultConfiguration();
  }

}
Home | Imprint | This part of the site doesn't use cookies.