getPluginId example

/** * Gets the plugin for this component. * * @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts * An array of contexts to set on the plugin. * * @return \Drupal\Component\Plugin\PluginInspectionInterface * The plugin. */
  public function getPlugin(array $contexts = []) {
    $plugin = $this->pluginManager()->createInstance($this->getPluginId()$this->getConfiguration());
    if ($contexts && $plugin instanceof ContextAwarePluginInterface) {
      $this->contextHandler()->applyContextMapping($plugin$contexts);
    }
    return $plugin;
  }

  /** * Wraps the component plugin manager. * * @return \Drupal\Core\Block\BlockManagerInterface * The plugin manager. */
    // \Drupal\Core\Config\Entity\ConfigEntityBase::set() that handles     // \Drupal\Core\Entity\EntityWithPluginCollectionInterface.     $layout_settings = $this->doGetLayout($layout_id$layout_settings)->getConfiguration();
    $this->setThirdPartySetting('field_layout', 'settings', $layout_settings);
    return $this;
  }

  /** * Implements \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface::setLayout(). */
  public function setLayout(LayoutInterface $layout) {
    $this->setLayoutId($layout->getPluginId()$layout->getConfiguration());
    return $this;
  }

  /** * Implements \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface::getLayout(). */
  public function getLayout() {
    return $this->doGetLayout($this->getLayoutId()$this->getLayoutSettings());
  }

  /** * Gets the layout plugin. * * @param string $layout_id * A layout plugin ID. * @param array $layout_settings * An array of settings. * * @return \Drupal\Core\Layout\LayoutInterface * The layout plugin. */
    $this->assertEquals(2, $this->getImageCount($style, 'public')new FormattableMarkup('Image style %style image %file successfully generated.', ['%style' => $style->label(), '%file' => $image_path]));

    // Create an image for the 'private' wrapper.     $image_path = $this->createSampleImage($style, 'private');
    $this->assertEquals(1, $this->getImageCount($style, 'private')new FormattableMarkup('Image style %style image %file successfully generated.', ['%style' => $style->label(), '%file' => $image_path]));

    // Remove the 'image_scale' effect and updates the style, which in turn     // forces an image style flush.     $style_path = 'admin/config/media/image-styles/manage/' . $style->id();
    $uuids = [];
    foreach ($style->getEffects() as $uuid => $effect) {
      $uuids[$effect->getPluginId()] = $uuid;
    }
    $this->drupalGet($style_path . '/effects/' . $uuids['image_scale'] . '/delete');
    $this->submitForm([], 'Delete');
    $this->assertSession()->statusCodeEquals(200);
    $this->drupalGet($style_path);
    $this->submitForm([], 'Save');
    $this->assertSession()->statusCodeEquals(200);

    // Post flush, expected 1 image in the 'public' wrapper (sample.png).     $this->assertEquals(1, $this->getImageCount($style, 'public')new FormattableMarkup('Image style %style flushed correctly for %wrapper wrapper.', ['%style' => $style->label(), '%wrapper' => 'public']));

    


  /** * Ensure that a certain handler is an instance of a certain table/field. * * @internal */
  public function assertInstanceHandler(ViewsHandlerInterface $handler, string $table, string $field, string $id): void {
    $table_data = $this->container->get('views.views_data')->get($table);
    $field_data = $table_data[$field][$id];

    $this->assertEquals($handler->getPluginId()$field_data['id']);
  }

}
'#type' => 'number',
      '#title' => $this->t('Trim link text length'),
      '#field_suffix' => $this->t('characters'),
      '#default_value' => $this->getSetting('trim_length'),
      '#min' => 1,
      '#description' => $this->t('Leave blank to allow unlimited link text lengths.'),
    ];
    $elements['url_only'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('URL only'),
      '#default_value' => $this->getSetting('url_only'),
      '#access' => $this->getPluginId() == 'link',
    ];
    $elements['url_plain'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Show URL as plain text'),
      '#default_value' => $this->getSetting('url_plain'),
      '#access' => $this->getPluginId() == 'link',
      '#states' => [
        'visible' => [
          ':input[name*="url_only"]' => ['checked' => TRUE],
        ],
      ],
    ];
return $entityType->getLabel();
  }

  /** * {@inheritdoc} */
  public function getOperations() {
    return [
      'list' => [
        'title' => $this->t('List'),
        'url' => Url::fromRoute('config_translation.entity_list', [
          'mapper_id' => $this->getPluginId(),
        ]),
      ],
    ];
  }

  /** * {@inheritdoc} */
  public function getContextualLinkGroup() {
    // @todo Contextual groups do not map to entity types in a predictable     // way. See https://www.drupal.org/node/2134841 to make them predictable.
/** * @dataProvider providerTestGetPluginId * @covers ::getPluginId */
  public function testGetPluginId($plugin_id$expected) {
    $plugin_base = $this->getMockForAbstractClass('Drupal\Component\Plugin\PluginBase', [
      [],
      $plugin_id,
      [],
    ]);

    $this->assertEquals($expected$plugin_base->getPluginId());
  }

  /** * Returns test data for testGetPluginId(). * * @return array */
  public function providerTestGetPluginId() {
    return [
      ['base_id', 'base_id'],
      ['base_id:derivative', 'base_id:derivative'],
    ];

  public function buildForm(array $form, FormStateInterface $form_state, MenuLinkInterface $menu_link_plugin = NULL) {
    $form['menu_link_id'] = [
      '#type' => 'value',
      '#value' => $menu_link_plugin->getPluginId(),
    ];
    $class_name = $menu_link_plugin->getFormClass();
    $form['#plugin_form'] = $this->classResolver->getInstanceFromDefinition($class_name);
    $form['#plugin_form']->setMenuLinkInstance($menu_link_plugin);

    $form += $form['#plugin_form']->buildConfigurationForm($form$form_state);

    $form['actions'] = ['#type' => 'actions'];
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Save'),
      
      ->setName('field_multiwidgetfield');

    $widget_options = [
      'field_definition' => $base_field_definition,
      'form_mode' => 'default',
      'configuration' => [
        'type' => 'test_field_widget_multiple',
      ],
    ];

    $instance = $widget_plugin_manager->getInstance($widget_options);
    $this->assertEquals('test_field_widget_multiple', $instance->getPluginId());

    // Now do the same but with machine name field_onewidgetfield, because that     // makes isApplicable() return FALSE.     $base_field_definition->setName('field_onewidgetfield');
    $instance = $widget_plugin_manager->getInstance($widget_options);

    // Instance should be default widget.     $this->assertNotSame('test_field_widget_multiple', $instance->getPluginId());
    $this->assertEquals('test_field_widget', $instance->getPluginId());
  }

}
$this->view = $view;

    // Load extenders as soon as possible.     $display['display_options'] += ['display_extenders' => []];
    $this->extenders = [];
    if ($extenders = Views::getEnabledDisplayExtenders()) {
      $manager = Views::pluginManager('display_extender');
      $display_extender_options = $display['display_options']['display_extenders'];
      foreach ($extenders as $extender) {
        /** @var \Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase $plugin */
        if ($plugin = $manager->createInstance($extender)) {
          $extender_options = isset($display_extender_options[$plugin->getPluginId()]) ? $display_extender_options[$plugin->getPluginId()] : [];
          $plugin->init($this->view, $this$extender_options);
          $this->extenders[$extender] = $plugin;
        }
      }
    }

    $this->setOptionDefaults($this->options, $this->defineOptions());
    $this->display = &$display;

    // Track changes that the user should know about.     $changed = FALSE;

    
public function sort() {
    uasort($this->instanceIds, [$this, 'sortHelper']);
    return $this;
  }

  /** * Provides uasort() callback to sort plugins. */
  public function sortHelper($aID$bID) {
    $a = $this->get($aID);
    $b = $this->get($bID);
    return strnatcasecmp($a->getPluginId()$b->getPluginId());
  }

  /** * {@inheritdoc} */
  public function getConfiguration() {
    $instances = [];
    // Store the current order of the instances.     $current_order = $this->instanceIds;
    // Reorder the instances to match the original order, adding new instances     // to the end.
/** * {@inheritdoc} */
  public function getInstance(array $options) {
    if (!isset($options['target_type'])) {
      throw new \InvalidArgumentException("Missing required 'target_type' property for a EntityReferenceSelection plugin.");
    }

    // Initialize default options.     $options += [
      'handler' => $this->getPluginId($options['target_type'], 'default'),
    ];

    // A specific selection plugin ID was already specified.     if (str_contains($options['handler'], ':')) {
      $plugin_id = $options['handler'];
    }
    // Only a selection group name was specified.     else {
      $plugin_id = $this->getPluginId($options['target_type']$options['handler']);
    }
    unset($options['handler']);

    
if ($links !== FALSE) {
      // We expect exactly two calls, one for the first call, and one after the       // cache clearing below.       $this->menuLinkManager->expects($this->exactly(2))
        ->method('loadLinksbyRoute')
        ->with('baby_llama')
        ->willReturn($links);
      if ($expected_link !== NULL) {
        $this->menuLinkManager->expects($this->exactly(2))
          ->method('getParentIds')
          ->willReturnMap([
            [$expected_link->getPluginId()$expected_trail_ids],
          ]);
      }
    }

    // Call out the same twice in order to ensure that static caching works.     $this->assertSame($expected_trail_ids$this->menuActiveTrail->getActiveTrailIds($menu_name));
    $this->assertSame($expected_trail_ids$this->menuActiveTrail->getActiveTrailIds($menu_name));

    $this->menuActiveTrail->clear();
    $this->assertSame($expected_trail_ids$this->menuActiveTrail->getActiveTrailIds($menu_name));
  }

  

  }

  /** * Returns generic default configuration for block plugins. * * @return array * An associative array with the default configuration. */
  protected function baseConfigurationDefaults() {
    return [
      'id' => $this->getPluginId(),
      'label' => '',
      'label_display' => BlockPluginInterface::BLOCK_LABEL_VISIBLE,
      'provider' => $this->pluginDefinition['provider'],
    ];
  }

  /** * {@inheritdoc} */
  public function defaultConfiguration() {
    return [];
  }
$widget_settings = \Drupal::service('plugin.manager.field.widget')->getDefaultSettings($default_widget);
    $expected = [
      'weight' => 3,
      'type' => $default_widget,
      'settings' => $widget_settings,
      'third_party_settings' => [],
    ];
    $this->assertEquals($expected$form_display->getComponent($field_name));

    // Check that the getWidget() method returns the correct widget plugin.     $widget = $form_display->getRenderer($field_name);
    $this->assertEquals($default_widget$widget->getPluginId());
    $this->assertEquals($widget_settings$widget->getSettings());

    // Check that the widget is statically persisted.     $this->assertSame($widget$form_display->getRenderer($field_name));

    // Check that changing the definition creates a new widget.     $form_display->setComponent($field_name[
      'type' => 'field_test_multiple',
    ]);
    $renderer = $form_display->getRenderer($field_name);
    $this->assertEquals('test_field_widget', $renderer->getPluginId());
    
Home | Imprint | This part of the site doesn't use cookies.