setConfiguration example

/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    // Ensure that an instantiated container in the global state of \Drupal from     // a previous test does not leak into this test.     \Drupal::unsetContainer();

    // Ensure that the NullFileCache implementation is used for the FileCache as     // unit tests should not be relying on caches implicitly.     FileCacheFactory::setConfiguration([FileCacheFactory::DISABLE_CACHE => TRUE]);
    // Ensure that FileCacheFactory has a prefix.     FileCacheFactory::setPrefix('prefix');

    $this->root = dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2);
  }

  /** * {@inheritdoc} */
  public function __get(string $name) {
    if ($name === 'randomGenerator') {
      
/** * {@inheritdoc} */
  public function setConfiguration(array $configuration) {
    if (isset($configuration['settings']['allowed_html'])) {
      // The javascript in core/modules/filter/filter.filter_html.admin.js       // removes new lines and double spaces so, for consistency when javascript       // is disabled, remove them.       $configuration['settings']['allowed_html'] = preg_replace('/\s+/', ' ', $configuration['settings']['allowed_html']);
    }
    parent::setConfiguration($configuration);
    // Force restrictions to be calculated again.     $this->restrictions = NULL;
  }

  /** * {@inheritdoc} */
  public function process($text$langcode) {
    $restrictions = $this->getHtmlRestrictions();
    // Split the work into two parts. For filtering HTML tags out of the content     // we rely on the well-tested Xss::filter() code. Since there is no '*' tag
$configuration = $this instanceof ConfigurableInterface ? $this->getConfiguration() : $this->configuration;
    return $configuration['context_mapping'] ?? [];
  }

  /** * {@inheritdoc} */
  public function setContextMapping(array $context_mapping) {
    if ($this instanceof ConfigurableInterface) {
      $configuration = $this->getConfiguration();
      $configuration['context_mapping'] = array_filter($context_mapping);
      $this->setConfiguration($configuration);
    }
    else {
      $this->configuration['context_mapping'] = $context_mapping;
    }
    return $this;
  }

  /** * {@inheritdoc} */
  abstract public function getPluginDefinition();

  
return $this->configuration;
    }
  }

  /** * {@inheritdoc} */
  public function setConfiguration($configuration) {
    $this->configuration = $configuration;
    $plugin = $this->get($this->instanceId);
    if ($plugin instanceof ConfigurableInterface) {
      $plugin->setConfiguration($configuration);
    }
    return $this;
  }

  /** * {@inheritdoc} */
  public function addInstanceId($id$configuration = NULL) {
    $this->instanceId = $id;
    // Reset the list of instance IDs since there can be only one.     $this->instanceIds = [];
    
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  }

  /** * {@inheritdoc} */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state->getValues();
    $transition = $form_state->get('transition');
    $configuration = $this->workflowType->getConfiguration();
    $configuration['transitions'][$transition->id()] = $values + $configuration['transitions'][$transition->id()];
    $this->workflowType->setConfiguration($configuration);
  }

}
$media_type = $this->createMediaType('oembed:video');
    $source = $media_type->getSource();

    // Add some HTML to the global site slogan, and use the site:slogan token in     // the thumbnail path, in order to prove that the final thumbnail path is     // stripped of HTML tags, and XML entities are decoded.     $this->config('system.site')
      ->set('slogan', '<h1>this&amp;that</h1>')
      ->save();
    $configuration = $source->getConfiguration();
    $configuration['thumbnails_directory'] .= '/[site:slogan]';
    $source->setConfiguration($configuration);
    $media_type->save();

    $media = Media::create([
      'bundle' => $media_type->id(),
      $source->getSourceFieldDefinition($media_type)->getName() => $this->randomString(),
    ]);
    $media->save();

    // The thumbnail directory should include the current date, as per the     // default configuration of the oEmbed source plugin.     $date = date('Y-m', $this->container->get('datetime.time')->getRequestTime());

    
    // configuration that was exported before this change was introduced.     $this->assertFalse(isset($configuration['default_moderation_state']));
    $legacy_configuration_node = Node::create([
      'title' => 'Test title',
      'type' => 'example',
    ]);
    $this->assertEquals('draft', $legacy_configuration_node->moderation_state->value);
    $legacy_configuration_node->save();
    $this->assertEquals('draft', $legacy_configuration_node->moderation_state->value);

    $configuration['default_moderation_state'] = 'published';
    $workflow->getTypePlugin()->setConfiguration($configuration);
    $workflow->save();

    $updated_default_node = Node::create([
      'title' => 'Test title',
      'type' => 'example',
    ]);
    $this->assertEquals('published', $updated_default_node->moderation_state->value);
    $legacy_configuration_node->save();
    $this->assertEquals('published', $updated_default_node->moderation_state->value);
  }

  
    $subform_state = SubformState::createForSubform($form['settings']$form$form_state);
    $this->getPluginForm($this->block)->submitConfigurationForm($form$subform_state);

    // If this block is context-aware, set the context mapping.     if ($this->block instanceof ContextAwarePluginInterface) {
      $this->block->setContextMapping($subform_state->getValue('context_mapping', []));
    }

    $configuration = $this->block->getConfiguration();

    $section = $this->sectionStorage->getSection($this->delta);
    $section->getComponent($this->uuid)->setConfiguration($configuration);

    $this->layoutTempstoreRepository->set($this->sectionStorage);
    $form_state->setRedirectUrl($this->sectionStorage->getLayoutBuilderUrl());
  }

  /** * {@inheritdoc} */
  protected function successfulAjaxSubmit(array $form, FormStateInterface $form_state) {
    return $this->rebuildAndClose($this->sectionStorage);
  }

  
// Ensure the caption filter works for linked images.     $input = '<a href="http://example.com/llamas/are/awesome/but/kittens/are/cool/too"><img src="llama.jpg" data-caption="Loquacious llama!" /></a>';
    $expected = '<figure role="group"><a href="http://example.com/llamas/are/awesome/but/kittens/are/cool/too"><img src="llama.jpg" /></a>' . "\n" . '<figcaption>Loquacious llama!</figcaption></figure>';
    $output = $test($input);
    $this->assertSame($expected$output->getProcessedText());
    $this->assertSame($attached_library$output->getAttachments());

    // So far we've tested that the caption filter works correctly. But we also     // want to make sure that it works well in tandem with the "Limit allowed     // HTML tags" filter, which it is typically used with.     $html_filter = $this->filters['filter_html'];
    $html_filter->setConfiguration([
      'settings' => [
        'allowed_html' => '<img src data-align data-caption>',
        'filter_html_help' => 1,
        'filter_html_nofollow' => 0,
      ],
    ]);
    $test_with_html_filter = function D$input) use ($filter$html_filter$renderer) {
      return $renderer->executeInRenderContext(new RenderContext()function D) use ($input$filter$html_filter) {
        // 1. Apply HTML filter's processing step.         $output = $html_filter->process($input, 'und');
        // 2. Apply caption filter's processing step.


            if (isset($media[$number])) {
                $product->setMedia($media[$number]);
            }

            if (isset($properties[$number])) {
                $product->setPropertySet($properties[$number]);
            }

            if (isset($configuration[$number])) {
                $product->setConfiguration($configuration[$number]);
            }

            $products[$number] = $product;
        }

        return $products;
    }
}

  protected $pluginDefinition;

  /** * {@inheritdoc} */
  public function __construct(array $configuration$plugin_id$plugin_definition) {
    parent::__construct($configuration$plugin_id$plugin_definition);
    $this->setConfiguration($configuration);
  }

  /** * {@inheritdoc} */
  public function build(array $regions) {
    // Ensure $build only contains defined regions and in the order defined.     $build = [];
    foreach ($this->getPluginDefinition()->getRegionNames() as $region_name) {
      if (array_key_exists($region_name$regions)) {
        $build[$region_name] = $regions[$region_name];
      }
'id' => 'rest_workflow',
      'label' => 'REST Workflow',
      'type' => 'workflow_type_complex_test',
    ]);
    $workflow
      ->getTypePlugin()
      ->addState('draft', 'Draft')
      ->addState('published', 'Published');
    $configuration = $workflow->getTypePlugin()->getConfiguration();
    $configuration['example_setting'] = 'foo';
    $configuration['states']['draft']['extra'] = 'bar';
    $workflow->getTypePlugin()->setConfiguration($configuration);
    $workflow->save();
    return $workflow;
  }

  /** * {@inheritdoc} */
  protected function getExpectedNormalizedEntity() {
    return [
      'dependencies' => [
        'module' => [
          

  protected function updateEntity(EntityInterface $entity, Row $row) {
    parent::updateEntity($entity$row);
    $entity->setPlugin($row->getDestinationProperty('plugin'));
    // The user_search plugin does not have a setConfiguration() method.     $plugin = $entity->getPlugin();
    if ($plugin instanceof ConfigurableSearchPluginBase) {
      $plugin->setConfiguration($row->getDestinationProperty('configuration'));
    }
  }

}
/** * Provides a base implementation for a configurable Action plugin. */
abstract class ConfigurableActionBase extends ActionBase implements ConfigurableInterface, DependentPluginInterface, PluginFormInterface {

  /** * {@inheritdoc} */
  public function __construct(array $configuration$plugin_id$plugin_definition) {
    parent::__construct($configuration$plugin_id$plugin_definition);

    $this->setConfiguration($configuration);
  }

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

  /** * {@inheritdoc} */

  protected function saveInlineBlockComponent(EntityInterface $entity, SectionComponent $component$new_revision$duplicate_blocks) {
    /** @var \Drupal\layout_builder\Plugin\Block\InlineBlock $plugin */
    $plugin = $component->getPlugin();
    $pre_save_configuration = $plugin->getConfiguration();
    $plugin->saveBlockContent($new_revision$duplicate_blocks);
    $post_save_configuration = $plugin->getConfiguration();
    if ($duplicate_blocks || (empty($pre_save_configuration['block_revision_id']) && !empty($post_save_configuration['block_revision_id']))) {
      $this->usage->addUsage($this->getPluginBlockId($plugin)$entity);
    }
    $component->setConfiguration($post_save_configuration);
  }

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