10.5 插件发现

龵龴龱龰龯龫Drupal龕龔龱龰龑龐龵龴龎龋龊龈龅龁齿齼龐龵龴齻齹齸齶齲齰龰龵龴龱龰齮齭齫齨龵龴齧龊齤齢齞齝齛龈齗齖龁 龵龴龱龰齕龴齰龰齓DiscoveryInterface鼶鼳齫鼲鼶鼳鼮鼬齓鼫鼩龵龴龱龰龎齻鼥鼢鼡鼟龎齮齭龁

齨core/lib/Drupal/Component/Plugin/Discovery/DiscoveryInterface.php齢鼇鼄鼂鼁黽黻黹黸黴

<?php

namespace Drupal\Component\Plugin\Discovery;

/**
 * An interface defining the minimum requirements of building a plugin
 * discovery component.
 *
 * @ingroup plugin_api
 */
interface DiscoveryInterface {

  /**
   * Gets a specific plugin definition.
   *
   * @param string $plugin_id
   *   A plugin id.
   * @param bool $exception_on_invalid
   *   (optional) If TRUE, an invalid plugin ID will throw an exception.
   *
   * @return mixed
   *   A plugin definition, or NULL if the plugin ID is invalid and
   *   $exception_on_invalid is FALSE.
   *
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   *   Thrown if $plugin_id is invalid and $exception_on_invalid is TRUE.
   */
  public function getDefinition($plugin_id, $exception_on_invalid = TRUE);

  /**
   * Gets the definition of all plugins for this type.
   *
   * @return mixed[]
   *   An array of plugin definitions (empty array if no definitions were
   *   found). Keys are plugin IDs.
   */
  public function getDefinitions();

  /**
   * Indicates if a specific plugin definition exists.
   *
   * @param string $plugin_id
   *   A plugin ID.
   *
   * @return bool
   *   TRUE if the definition exists, FALSE otherwise.
   */
  public function hasDefinition($plugin_id);

}
  • getDefinition: 麝麙龫鼮龎龵龴鼮鼬齮齭
  • getDefinitions: 麝麙龵龴鼮鼬龎麗麖
  • hasDefinition: 龫麓龵龴鼮鼬龯麑麏齨

黽鼩齰龰麎鼮鼬龎龵龴龱龰齻麍麌齨src\Plugin\Discovery\HelloWorldDiscovery.php齢齰龰DiscoveryInterface龁

Drupal8麁鹾鹺鹷鹵鹲龐鹮鹫龎龵龴龱龰齻齹黴

1.StaticDiscovery

StaticDiscovery鹦鹤齨龵龴龱龰齻齢鹣鼶鹢鹟龵龴龁齨齻齢龎protected鹝鹜$definitions麏鹘齓鹖鼟鹔龈齮齭setDefinition()鹢鹟龎龵龴鼮鼬龁鼫鼩鹔龈鹓龐齮齭鼮鼬龎龵龴鼇鼄鹐鹌鹋龁

2.HookDiscovery

HookDiscovery齻鹦鹤鹄鹁Drupal龎hook_comonent_info()/hook_comonent_info_alter()鸾鸼龵龴龱龰龁鹄鹁鹓龐龵龴龱龰鸸鸵齫龵龴齧龊齤鸱鸰鸬鹁hook鸫麝麙鼇鹁龎龵龴鸧鸦龁

3.AnnotatedClassDiscovery

AnnotatedClassDiscovery鸞鹢齗齻龱龰齫鼲龱龰鸸鸵鹦鹤鸛齨鼮鼬龵龴龎齻龎鸚龴齢龵鸗鹢齗齫齨鹢齗齢鸕鸑鸎鸊龎鸈鸇鼮鼬龵龴鹢齗齻齫AnnotatedClassDiscovery鸰鸃鹓鷿鸚龴鸾鸼鷽鷺齫鷸鷵龱龰龵龴龁

4.YamlDiscovery

YamlDiscovery鹦鹤鸛齨yaml鸚龴齢鼮鼬龵龴齻齹龁Drupal鷬鷫鷨齲鸱鷧鹁齨local task鷣local action鷟龁

本书共79小节:

评论 (写第一个评论)