class CommentPermalinkFormatter
Same name and namespace in other branches
- 11.x core/modules/comment/src/Plugin/Field/FieldFormatter/CommentPermalinkFormatter.php \Drupal\comment\Plugin\Field\FieldFormatter\CommentPermalinkFormatter
Plugin implementation of the 'comment_permalink' formatter.
All the other entities use 'canonical' or 'revision' links to link the entity to itself but comments use permalink URL.
Plugin annotation
@FieldFormatter(
id = "comment_permalink",
label = @Translation("Comment Permalink"),
field_types = {
"string",
"uri",
},
quickedit = {
"editor" = "plain_text"
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
- class \Drupal\Core\Field\PluginSettingsBase extends \Drupal\Core\Field\PluginSettingsInterface, \Drupal\Component\Plugin\DependentPluginInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Field\FormatterBase extends \Drupal\Core\Field\FormatterInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface implements \Drupal\Core\Field\PluginSettingsBase
- class \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter implements \Drupal\Core\Field\FormatterBase
- class \Drupal\comment\Plugin\Field\FieldFormatter\CommentPermalinkFormatter implements \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter
- class \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter implements \Drupal\Core\Field\FormatterBase
- class \Drupal\Core\Field\FormatterBase extends \Drupal\Core\Field\FormatterInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface implements \Drupal\Core\Field\PluginSettingsBase
- class \Drupal\Core\Field\PluginSettingsBase extends \Drupal\Core\Field\PluginSettingsInterface, \Drupal\Component\Plugin\DependentPluginInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of CommentPermalinkFormatter
File
-
core/
modules/ comment/ src/ Plugin/ Field/ FieldFormatter/ CommentPermalinkFormatter.php, line 28
Namespace
Drupal\comment\Plugin\Field\FieldFormatterView source
class CommentPermalinkFormatter extends StringFormatter {
/**
* {@inheritdoc}
*/
protected function getEntityUrl(EntityInterface $comment) {
/** @var \Drupal\comment\CommentInterface $comment */
$comment_permalink = $comment->permalink();
if ($comment->hasField('comment_body') && $body = $comment->get('comment_body')->value) {
$attributes = $comment_permalink->getOption('attributes') ?: [];
$attributes += [
'title' => Unicode::truncate($body, 128),
];
$comment_permalink->setOption('attributes', $attributes);
}
return $comment_permalink;
}
/**
* {@inheritdoc}
*/
public static function isApplicable(FieldDefinitionInterface $field_definition) {
return parent::isApplicable($field_definition) && $field_definition->getTargetEntityTypeId() === 'comment' && $field_definition->getName() === 'subject';
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.