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小节:

评论 (写第一个评论)