You are here

class CommentStyleguide in Style Guide 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/Styleguide/CommentStyleguide.php \Drupal\styleguide\Plugin\Styleguide\CommentStyleguide

Comment Styleguide items implementation.

Plugin annotation


@Plugin(
  id = "comment_styleguide",
  label = @Translation("Comment Styleguide elements")
)

Hierarchy

Expanded class hierarchy of CommentStyleguide

File

src/Plugin/Styleguide/CommentStyleguide.php, line 19

Namespace

Drupal\styleguide\Plugin\Styleguide
View source
class CommentStyleguide extends StyleguidePluginBase {

  /**
   * The styleguide generator service.
   *
   * @var \Drupal\styleguide\Generator
   */
  protected $generator;

  /**
   * The module handler service.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Constructs a new CommentStyleguide.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param array $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\styleguide\GeneratorInterface $styleguide_generator
   *   The styleguide generator service.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler service.
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, GeneratorInterface $styleguide_generator, ModuleHandlerInterface $module_handler) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->generator = $styleguide_generator;
    $this->moduleHandler = $module_handler;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('styleguide.generator'), $container
      ->get('module_handler'));
  }

  /**
   * {@inheritdoc}
   */
  public function items() {
    $items = [];
    if ($this->moduleHandler
      ->moduleExists('comment')) {
      $items['comment'] = [
        'title' => $this
          ->t('Comment'),
        'content' => $this
          ->commentPrepare(),
        'group' => $this
          ->t('Comment'),
      ];
    }
    return $items;
  }

  /**
   * Helper method to prepare a fake comment.
   *
   * @return array
   *   A renderable array.
   */
  private function commentPrepare() {
    $comment = [
      'subject' => $this->generator
        ->words(5),
      'comment_type' => 'comment',
      'cid' => 0,
    ];
    return [
      '#theme' => 'comment',
      '#comment' => Comment::create($comment),
      '#comment_threaded' => TRUE,
      'content' => $this->generator
        ->paragraphs(),
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommentStyleguide::$generator protected property The styleguide generator service.
CommentStyleguide::$moduleHandler protected property The module handler service.
CommentStyleguide::commentPrepare private function Helper method to prepare a fake comment.
CommentStyleguide::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
CommentStyleguide::items public function Styleguide elements implementation. Overrides StyleguideInterface::items
CommentStyleguide::__construct public function Constructs a new CommentStyleguide. Overrides PluginBase::__construct
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
StyleguidePluginBase::buildLink public function Build a link.
StyleguidePluginBase::buildLinkFromRoute public function Build a link from a given route name and parameters.