class ContactLink
Same name and namespace in other branches
- 11.x core/modules/contact/src/Plugin/views/field/ContactLink.php \Drupal\contact\Plugin\views\field\ContactLink
- 10 core/modules/contact/src/Plugin/views/field/ContactLink.php \Drupal\contact\Plugin\views\field\ContactLink
Defines a field that links to the user contact page, if access is permitted.
Plugin annotation
@ViewsField("contact_link");
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\views\Plugin\views\PluginBase extends \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\views\Plugin\views\HandlerBase extends \Drupal\views\Plugin\views\ViewsHandlerInterface implements \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\field\FieldPluginBase extends \Drupal\views\Plugin\views\field\FieldHandlerInterface implements \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\field\LinkBase uses \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\views\Entity\Render\EntityTranslationRenderTrait implements \Drupal\views\Plugin\views\field\FieldPluginBase
- class \Drupal\contact\Plugin\views\field\ContactLink implements \Drupal\views\Plugin\views\field\LinkBase
- class \Drupal\views\Plugin\views\field\LinkBase uses \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\views\Entity\Render\EntityTranslationRenderTrait implements \Drupal\views\Plugin\views\field\FieldPluginBase
- class \Drupal\views\Plugin\views\field\FieldPluginBase extends \Drupal\views\Plugin\views\field\FieldHandlerInterface implements \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\HandlerBase extends \Drupal\views\Plugin\views\ViewsHandlerInterface implements \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\PluginBase extends \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface 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 ContactLink
Related topics
File
-
core/
modules/ contact/ src/ Plugin/ views/ field/ ContactLink.php, line 17
Namespace
Drupal\contact\Plugin\views\fieldView source
class ContactLink extends LinkBase {
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['text']['#title'] = $this->t('Link label');
$form['text']['#required'] = TRUE;
$form['text']['#default_value'] = empty($this->options['text']) ? $this->getDefaultLabel() : $this->options['text'];
}
/**
* {@inheritdoc}
*/
protected function getUrlInfo(ResultRow $row) {
return Url::fromRoute('entity.user.contact_form', [
'user' => $this->getEntity($row)
->id(),
]);
}
/**
* {@inheritdoc}
*/
protected function renderLink(ResultRow $row) {
$entity = $this->getEntity($row);
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['url'] = $this->getUrlInfo($row);
$title = $this->t('Contact %user', [
'%user' => $entity->label(),
]);
$this->options['alter']['attributes'] = [
'title' => $title,
];
if (!empty($this->options['text'])) {
return $this->options['text'];
}
else {
return $title;
}
}
/**
* {@inheritdoc}
*/
protected function getDefaultLabel() {
return $this->t('contact');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.