pluginManager example

    $form['validate']['type'] = [
      '#type' => 'select',
      '#title' => $this->t('Validator'),
      '#default_value' => static::encodeValidatorId($this->options['validate']['type']),
      '#states' => [
        'visible' => [
          ':input[name="options[specify_validation]"]' => ['checked' => TRUE],
        ],
      ],
    ];

    $plugins = Views::pluginManager('argument_validator')->getDefinitions();
    foreach ($plugins as $id => $info) {
      if (!empty($info['no_ui'])) {
        continue;
      }

      $valid = TRUE;
      if (!empty($info['type'])) {
        $valid = FALSE;
        if (empty($this->definition['validate type'])) {
          continue;
        }
        
$def['left_query'] = $this->leftQuery($this->options);
        \Drupal::cache('data')->set($cid$def['left_query']);
      }
    }

    if (!empty($def['join_id'])) {
      $id = $def['join_id'];
    }
    else {
      $id = 'subquery';
    }
    $join = Views::pluginManager('join')->createInstance($id$def);

    // use a short alias for this:     $alias = $def['table'] . '_' . $this->table;

    $this->alias = $this->query->addRelationship($alias$join$this->definition['base']$this->relationship);
  }

}
if (!empty($this->definition['extra'])) {
      $def['extra'] = $this->definition['extra'];
    }

    if (!empty($def['join_id'])) {
      $id = $def['join_id'];
    }
    else {
      $id = 'standard';
    }
    $join = Views::pluginManager('join')->createInstance($id$def);

    // use a short alias for this:     $alias = $def['table'] . '_' . $this->table;

    $this->alias = $this->query->addRelationship($alias$join$this->definition['base']$this->relationship);

    // Add access tags if the base table provide it.     if (empty($this->query->options['disable_sql_rewrite']) && isset($table_data['table']['base']['access query tag'])) {
      $access_tag = $table_data['table']['base']['access query tag'];
      $this->query->addTag($access_tag);
    }
  }
// If this is empty, it's a direct link.       if (empty($configuration['left_table'])) {
        $configuration['left_table'] = $base_table;
      }

      if (isset($join_info['arguments'])) {
        foreach ($join_info['arguments'] as $key => $argument) {
          $configuration[$key] = $argument;
        }
      }

      $join = Views::pluginManager('join')->createInstance($id$configuration);

      return $join;
    }
  }

  /** * {@inheritdoc} */
  public function getEntityType() {
    // If the user has configured a relationship on the handler take that into     // account.

  public function initDisplay() {
    if (isset($this->current_display)) {
      return TRUE;
    }

    // Initialize the display cache array.     $this->displayHandlers = new DisplayPluginCollection($this, Views::pluginManager('display'));

    $this->current_display = 'default';
    $this->display_handler = $this->displayHandlers->get('default');

    return TRUE;
  }

  /** * Gets the first display that is accessible to the user. * * @param array|string $displays * Either a single display id or an array of display ids. * * @return string * The first accessible display id, at least default. */

  public static function fetchPluginNames($type$key = NULL, array $base = []) {
    $definitions = static::pluginManager($type)->getDefinitions();
    $plugins = [];

    foreach ($definitions as $id => $plugin) {
      // Skip plugins that don't conform to our key, if they have one.       if ($key && isset($plugin['display_types']) && !in_array($key$plugin['display_types'])) {
        continue;
      }

      if (empty($plugin['no_ui']) && (empty($base) || empty($plugin['base']) || array_intersect($base$plugin['base']))) {
        $plugins[$id] = $plugin['title'];
      }
    }
/** * 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. */
$search_condition = $this->view->query->getConnection()->condition('AND');

      // Create a new join to relate the 'search_total' table to our current       // 'search_index' table.       $definition = [
        'table' => 'search_total',
        'field' => 'word',
        'left_table' => $search_index,
        'left_field' => 'word',
      ];
      $join = Views::pluginManager('join')->createInstance('standard', $definition);
      $search_total = $this->query->addRelationship('search_total', $join$search_index);

      // Add the search score field to the query.       $this->search_score = $this->query->addField('', "$search_index.score * $search_total.count", 'score', ['function' => 'sum']);

      // Add the conditions set up by the search query to the views query.       $search_condition->condition("$search_index.type", $this->searchType);
      $search_dataset = $this->query->addTable('node_search_dataset');
      $conditions = $this->searchQuery->conditions();
      $condition_conditions =& $conditions->conditions();
      foreach ($condition_conditions as $key => &$condition) {
        

  protected function buildFormStyle(array &$form, FormStateInterface $form_state$type) {
    $style_form = &$form['displays'][$type]['options']['style'];
    $style = $style_form['style_plugin']['#default_value'];
    $style_plugin = Views::pluginManager('style')->createInstance($style);
    if (isset($style_plugin) && $style_plugin->usesRowPlugin()) {
      $options = $this->rowStyleOptions();
      $style_form['row_plugin'] = [
        '#type' => 'select',
        '#title' => $this->t('of'),
        '#options' => $options,
        '#access' => count($options) > 1,
      ];
      // For the block display, the default value should be "titles (linked)",       // if it's available (since that's the most common use case).       $block_with_linked_titles_available = ($type == 'block' && isset($options['titles_linked']));
      
'field' => 'content_entity_id',
            'left_field' => $left_entity_type->getKey('id'),
          ],
        ],
      ];
      if ($left_entity_type->isTranslatable()) {
        $configuration['extra'][] = [
          'field' => $entity_type->getKey('langcode'),
          'left_field' => $left_entity_type->getKey('langcode'),
        ];
      }
      $join = Views::pluginManager('join')->createInstance('standard', $configuration);
      $this->tableAlias = $this->query->addRelationship('content_moderation_state', $join, 'content_moderation_state_field_revision');
    }

    return $this->tableAlias;
  }

}
// Verify that the disabled display css class does not appears once the     // display is enabled again.     $this->submitForm([], 'Enable Page');
    $this->assertSession()->elementNotExists('xpath', "//div[contains(@class, 'views-display-disabled')]");
  }

  /** * Tests views_ui_views_plugins_display_alter is altering plugin definitions. */
  public function testDisplayPluginsAlter() {
    $definitions = Views::pluginManager('display')->getDefinitions();

    $expected = [
      'route_name' => 'entity.view.edit_form',
      'route_parameters_names' => ['view' => 'id'],
    ];

    // Test the expected views_ui array exists on each definition.     foreach ($definitions as $definition) {
      $this->assertSame($expected$definition['contextual links']['entity.view.edit_form'], 'Expected views_ui array found in plugin definition.');
    }
  }

  

    }

    $route_path = '/' . implode('/', $bits);

    $route = new Route($route_path$defaults);

    // Add access check parameters to the route.     $access_plugin = $this->getPlugin('access');
    if (!isset($access_plugin)) {
      // @todo Do we want to support a default plugin in getPlugin itself?       $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']));

    
return $label;
  }

  /** * {@inheritdoc} */
  public function addDisplay($plugin_id = 'page', $title = NULL, $id = NULL) {
    if (empty($plugin_id)) {
      return FALSE;
    }

    $plugin = Views::pluginManager('display')->getDefinition($plugin_id);

    if (empty($plugin)) {
      $plugin['title'] = t('Broken');
    }

    if (empty($id)) {
      $id = $this->generateDisplayId($plugin_id);

      // Generate a unique human-readable name by inspecting the counter at the       // end of the previous display ID, e.g., 'page_1'.       if ($id !== 'default') {
        


  /** * Assert the plugin states. * * @param string[] $states * The states which should appear in the filter. * * @internal */
  protected function assertPluginStates(array $states): void {
    $plugin = Views::pluginManager('filter')->createInstance('moderation_state_filter', []);
    $view = Views::getView('test_content_moderation_state_filter_base_table');
    $plugin->init($view$view->getDisplay());
    $this->assertEquals($states$plugin->getValueOptions());
  }

  /** * Assert the nodes appear when the test view is executed. * * @param \Drupal\node\NodeInterface[] $nodes * Nodes to assert are in the views result. * @param array $filters * An array of filters to apply to the view. * @param string $view_id * The view to execute for the results. * * @internal */
/** * {@inheritdoc} */
  public function initDisplay(ViewExecutable $view, array &$display, array &$options = NULL) {
    $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;
        }
      }
    }

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