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

评论 (写第一个评论)