You are here

trait ExecutablePluginTrait in Rules 8.3

Offers common methods for executable plugins.

Hierarchy

File

src/Core/ExecutablePluginTrait.php, line 10

Namespace

Drupal\rules\Core
View source
trait ExecutablePluginTrait {

  /**
   * Get the translated label from the plugin definition.
   *
   * @return string
   *   The label of the plugin.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   *   Thrown if the label is not defined for the plugin.
   */
  protected function getLabelValue() {
    $definition = $this
      ->getPluginDefinition();
    if (empty($definition['label'])) {
      throw new InvalidPluginDefinitionException('The label is not defined for plugin ' . $this
        ->getPluginId() . ' (' . __CLASS__ . ').');
    }

    // The label can be an instance of
    // \Drupal\Core\StringTranslation\TranslatableMarkup here, so make sure to
    // always return a primitive string representation here.
    return (string) $definition['label'];
  }

  /**
   * Get the translated summary from the label annotation.
   *
   * @return string
   *   The summary of the plugin.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   *   Thrown if a summary was not set.
   */
  public function summary() {
    return $this
      ->getLabelValue();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExecutablePluginTrait::getLabelValue protected function Get the translated label from the plugin definition.
ExecutablePluginTrait::summary public function Get the translated summary from the label annotation. 4