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

评论 (写第一个评论)