getPluginDefinition example


  public function getCacheKey($name): string {
    try {
      $component = $this->pluginManager->find($name);
    }
    catch (ComponentNotFoundException $e) {
      throw new LoaderError('Unable to find component');
    }
    return implode('--', array_filter([
      'sdc',
      $name,
      $component->getPluginDefinition()['provider'] ?? '',
    ]));
  }

  /** * {@inheritdoc} */
  public function isFresh(string $name, int $time): bool {
    $file_is_fresh = static fn(string $path) => filemtime($path) < $time;
    try {
      $component = $this->pluginManager->find($name);
    }
    
'#description' => $this->t('Link weight among links in the same menu at the same depth. In the menu, the links with high weight will sink and links with a low weight will be positioned nearer the top.'),
    ];

    return $form;
  }

  /** * {@inheritdoc} */
  public function extractFormValues(array &$form, FormStateInterface $form_state) {
    // Start from the complete, original, definition.     $new_definition = $this->menuLink->getPluginDefinition();
    // Since the ID may not be present in the definition used to construct the     // plugin, add it here so it's available to any consumers of this method.     $new_definition['id'] = $form_state->getValue('id');
    $new_definition['enabled'] = $form_state->getValue('enabled') ? 1 : 0;
    $new_definition['weight'] = (int) $form_state->getValue('weight');
    $new_definition['expanded'] = $form_state->getValue('expanded') ? 1 : 0;
    [$menu_name$parent] = explode(':', $form_state->getValue('menu_parent'), 2);
    if (!empty($menu_name)) {
      $new_definition['menu_name'] = $menu_name;
    }
    if (isset($parent)) {
      
$changed = parent::onDependencyRemoval($dependencies);
    foreach ($dependencies['config'] as $entity) {
      if ($entity->getEntityTypeId() == 'field_config') {
        // Remove components for fields that are being deleted.         $this->removeComponent($entity->getName());
        unset($this->hidden[$entity->getName()]);
        $changed = TRUE;
      }
    }
    foreach ($this->getComponents() as $name => $component) {
      if ($renderer = $this->getRenderer($name)) {
        if (in_array($renderer->getPluginDefinition()['provider']$dependencies['module'])) {
          // Revert to the defaults if the plugin that supplies the widget or           // formatter depends on a module that is being uninstalled.           $this->setComponent($name);
          $changed = TRUE;
        }

        // Give this component the opportunity to react on dependency removal.         $component_removed_dependencies = $this->getPluginRemovedDependencies($renderer->calculateDependencies()$dependencies);
        if ($component_removed_dependencies) {
          if ($renderer->onDependencyRemoval($component_removed_dependencies)) {
            // Update component settings to reflect changes.


  /** * @covers ::setContextValue */
  public function testSetContextValue() {
    $typed_data_manager = $this->prophesize(TypedDataManagerInterface::class);
    $container = new ContainerBuilder();
    $container->set('typed_data_manager', $typed_data_manager->reveal());
    \Drupal::setContainer($container);

    $this->plugin->getPluginDefinition()->addContextDefinition('foo', new ContextDefinition('string'));

    $this->assertFalse($this->plugin->setContextCalled);
    $this->plugin->setContextValue('foo', new StringData(new DataDefinition(), 'bar'));
    $this->assertTrue($this->plugin->setContextCalled);
  }

}

class TestContextAwarePluginDefinition extends PluginDefinition implements ContextAwarePluginDefinitionInterface {

  use ContextAwarePluginDefinitionTrait;

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

  /** * {@inheritdoc} * * @return \Drupal\Core\Plugin\Context\ContextDefinitionInterface[] */
  public function getContextDefinitions() {
    $definition = $this->getPluginDefinition();
    if ($definition instanceof ContextAwarePluginDefinitionInterface) {
      return $definition->getContextDefinitions();
    }

    return !empty($definition['context_definitions']) ? $definition['context_definitions'] : [];
  }

  /** * {@inheritdoc} * * @return \Drupal\Core\Plugin\Context\ContextDefinitionInterface */
'1x',
        ],
        'provider' => 'breakpoint_theme_test',
        'id' => 'breakpoint_theme_test.tv',
        'group' => 'breakpoint_theme_test',
        'class' => 'Drupal\\breakpoint\\Breakpoint',
      ],
    ];

    $breakpoints = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup('breakpoint_theme_test');
    foreach ($expected_breakpoints as $id => $expected_breakpoint) {
      $this->assertEquals($expected_breakpoint$breakpoints[$id]->getPluginDefinition());
    }

    // Test that the order is as expected.     $this->assertSame(array_keys($expected_breakpoints)array_keys($breakpoints));
  }

  /** * Tests the custom breakpoint group provided by a theme and a module. */
  public function testCustomBreakpointGroups() {
    // Verify the breakpoint group for breakpoint_theme_test.group2 was created.
// The field item should get the Timestamp @DataType denormalization set as     // a value, in FieldItemNormalizer::denormalize().     $timestamp_item->setValue(['value' => $timestamp_data_denormalization])
      ->shouldBeCalled();

    // Avoid a static method call by returning dummy serialized property data.     $field_definition = $this->prophesize(FieldDefinitionInterface::class);
    $timestamp_item
      ->getFieldDefinition()
      ->willReturn($field_definition->reveal())
      ->shouldBeCalled();
    $timestamp_item->getPluginDefinition()
      ->willReturn([
        'serialized_property_names' => [
          'foo' => 'bar',
        ],
      ])
      ->shouldBeCalled();
    $entity = $this->prophesize(EntityInterface::class);
    $entity_type = $this->prophesize(EntityTypeInterface::class);
    $entity->getEntityType()
      ->willReturn($entity_type->reveal())
      ->shouldBeCalled();
    
/** * {@inheritdoc} */
  public function executeMultiple(array $entities) {
    /** @var \Drupal\Core\Entity\EntityInterface[] $entities */
    $selection = [];
    foreach ($entities as $entity) {
      $langcode = $entity->language()->getId();
      $selection[$entity->id()][$langcode] = $langcode;
    }
    $this->tempStore->set($this->currentUser->id() . ':' . $this->getPluginDefinition()['type']$selection);
  }

  /** * {@inheritdoc} */
  public function execute($object = NULL) {
    $this->executeMultiple([$object]);
  }

  /** * {@inheritdoc} */
$values['label'] = $this->t('@label (@type)', [
          '@label' => $values['label'],
          '@type' => $row->getSourceProperty('name'),
        ]);
        $values['source']['bundle'] = $bundle;
        $values['destination']['default_bundle'] = $bundle;

        /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
        $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($values);
        $this->fieldDiscovery->addBundleFieldProcesses($migration, 'taxonomy_term', $bundle);
        $this->derivatives[$bundle] = $migration->getPluginDefinition();
      }
    }
    catch (DatabaseExceptionWrapper $e) {
      // Once we begin iterating the source plugin it is possible that the       // source tables will not exist. This can happen when the       // MigrationPluginManager gathers up the migration definitions but we do       // not actually have a Drupal 7 source database.     }

    return $this->derivatives;
  }

}
/** * Tests search plugin annotation and interfaces. */
  public function testAnnotation() {
    /** @var \Drupal\search\SearchPluginManager $manager */
    $manager = \Drupal::service('plugin.manager.search');
    /** @var \Drupal\help_topics\Plugin\Search\HelpSearch $plugin */
    $plugin = $manager->createInstance('help_search');
    $this->assertInstanceOf(AccessibleInterface::class$plugin);
    $this->assertInstanceOf(SearchIndexingInterface::class$plugin);
    $this->assertSame('Help', (string) $plugin->getPluginDefinition()['title']);
    $this->assertTrue($plugin->usesAdminTheme());
  }

}
public function testOnBuildRenderInPreviewEmptyBuild() {
    $block = $this->prophesize(BlockPluginInterface::class)->willImplement(PreviewFallbackInterface::class);

    $block->access($this->account->reveal(), TRUE)->shouldNotBeCalled();
    $block->getCacheContexts()->willReturn([]);
    $block->getCacheTags()->willReturn(['test']);
    $block->getCacheMaxAge()->willReturn(Cache::PERMANENT);
    $block->getConfiguration()->willReturn([]);
    $block->getPluginId()->willReturn('block_plugin_id');
    $block->getBaseId()->willReturn('block_plugin_id');
    $block->getDerivativeId()->willReturn(NULL);
    $block->getPluginDefinition()->willReturn(['admin_label' => 'adminlabel']);
    $placeholder_string = 'The placeholder string';
    $block->getPreviewFallbackString()->willReturn($placeholder_string);

    $block_content = [];
    $block->build()->willReturn($block_content);
    $this->blockManager->createInstance('some_block_id', ['id' => 'some_block_id'])->willReturn($block->reveal());

    $component = new SectionComponent('some-uuid', 'some-region', ['id' => 'some_block_id']);
    $event = new SectionComponentBuildRenderArrayEvent($component[], TRUE);

    $subscriber = new BlockComponentRenderArray($this->account->reveal());
    

  public function __construct(MenuLinkInterface $wrapped_link) {
    $this->wrappedLink = $wrapped_link;
    $plugin_definition = [
      'route_name' => '<front>',
      'route_parameters' => [],
      'url' => NULL,
    ] + $this->wrappedLink->getPluginDefinition();
    parent::__construct([]$this->wrappedLink->getPluginId()$plugin_definition);
  }

  /** * {@inheritdoc} */
  public function getTitle() {
    return $this->t('Inaccessible');
  }

  /** * {@inheritdoc} */
$links = [
      1 => MenuLinkMock::create(['id' => 'test.example1', 'route_name' => 'example1', 'title' => 'foo', 'parent' => '']),
      2 => MenuLinkMock::create(['id' => 'test.example2', 'route_name' => 'example2', 'title' => 'bar', 'parent' => 'test.example1', 'route_parameters' => ['foo' => 'bar']]),
      3 => MenuLinkMock::create(['id' => 'test.example3', 'route_name' => 'example3', 'title' => 'baz', 'parent' => 'test.example2', 'route_parameters' => ['baz' => 'qux']]),
      4 => MenuLinkMock::create(['id' => 'test.example4', 'route_name' => 'example4', 'title' => 'qux', 'parent' => 'test.example3']),
      5 => MenuLinkMock::create(['id' => 'test.example5', 'route_name' => 'example5', 'title' => 'foofoo', 'parent' => '']),
      6 => MenuLinkMock::create(['id' => 'test.example6', 'route_name' => '', 'url' => 'https://www.drupal.org/', 'title' => 'barbar', 'parent' => '']),
      7 => MenuLinkMock::create(['id' => 'test.example7', 'route_name' => 'example7', 'title' => 'bazbaz', 'parent' => '']),
      8 => MenuLinkMock::create(['id' => 'test.example8', 'route_name' => 'example8', 'title' => 'quxqux', 'parent' => '']),
    ];
    foreach ($links as $instance) {
      $this->menuLinkManager->addDefinition($instance->getPluginId()$instance->getPluginDefinition());
    }
    $parameters = new MenuTreeParameters();
    $tree = $this->linkTree->load('mock', $parameters);

    $count = function Darray $tree) {
      $sum = function D$carry, MenuLinkTreeElement $item) {
        return $carry + $item->count();
      };
      return array_reduce($tree$sum);
    };

    
      $access_plugin = Views::pluginManager('access')->createInstance('none');
    }
    $access_plugin->alterRouteDefinition($route);

    // Set the argument map, in order to support named parameters.     $route->setOption('_view_argument_map', $argument_map);
    $route->setOption('_view_display_plugin_id', $this->getPluginId());
    $route->setOption('_view_display_plugin_class', static::class);
    $route->setOption('_view_display_show_admin_links', $this->getOption('show_admin_links'));

    // Store whether the view will return a response.     $route->setOption('returns_response', !empty($this->getPluginDefinition()['returns_response']));

    // Symfony 4 requires that UTF-8 route patterns have the "utf8" option set     $route->setOption('utf8', TRUE);

    return $route;
  }

  /** * {@inheritdoc} */
  public function collectRoutes(RouteCollection $collection) {
    

  protected function buildAdministrativeSection(SectionStorageInterface $section_storage$delta) {
    $storage_type = $section_storage->getStorageType();
    $storage_id = $section_storage->getStorageId();
    $section = $section_storage->getSection($delta);

    $layout = $section->getLayout($this->getPopulatedContexts($section_storage));
    $layout_settings = $section->getLayoutSettings();
    $section_label = !empty($layout_settings['label']) ? $layout_settings['label'] : $this->t('Section @section', ['@section' => $delta + 1]);

    $build = $section->toRenderArray($this->getPopulatedContexts($section_storage), TRUE);
    $layout_definition = $layout->getPluginDefinition();

    $region_labels = $layout_definition->getRegionLabels();
    foreach ($layout_definition->getRegions() as $region => $info) {
      if (!empty($build[$region])) {
        foreach (Element::children($build[$region]) as $uuid) {
          $build[$region][$uuid]['#attributes']['class'][] = 'js-layout-builder-block';
          $build[$region][$uuid]['#attributes']['class'][] = 'layout-builder-block';
          $build[$region][$uuid]['#attributes']['data-layout-block-uuid'] = $uuid;
          $build[$region][$uuid]['#attributes']['data-layout-builder-highlight-id'] = $this->blockUpdateHighlightId($uuid);
          $build[$region][$uuid]['#contextual_links'] = [
            'layout_builder_block' => [
              
Home | Imprint | This part of the site doesn't use cookies.