class ContactLink in Drupal 10
Same name and namespace in other branches
- 8 core/modules/contact/src/Plugin/views/field/ContactLink.php \Drupal\contact\Plugin\views\field\ContactLink
- 9 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\views\Plugin\views\field\LinkBase extends \Drupal\views\Plugin\views\field\FieldPluginBase uses RedirectDestinationTrait, EntityTranslationRenderTrait
- class \Drupal\contact\Plugin\views\field\ContactLink
Expanded class hierarchy of ContactLink
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');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContactLink:: |
public | function |
Overrides LinkBase:: |
|
ContactLink:: |
protected | function |
Returns the default label for this link. Overrides LinkBase:: |
|
ContactLink:: |
protected | function |
Returns the URI elements of the link. Overrides LinkBase:: |
|
ContactLink:: |
protected | function |
Prepares the link to view an entity. Overrides LinkBase:: |
|
EntityTranslationRenderTrait:: |
protected | property | The renderer to be used to render the entity row. | |
EntityTranslationRenderTrait:: |
public | function | Returns the entity translation matching the configured row language. | |
EntityTranslationRenderTrait:: |
protected | function | Returns the current renderer. | |
LinkBase:: |
protected | property | The access manager service. | |
LinkBase:: |
protected | property | Current user object. | |
LinkBase:: |
protected | property | The entity repository. | |
LinkBase:: |
protected | property | The entity type manager. | |
LinkBase:: |
protected | property | The language manager. | |
LinkBase:: |
protected | function | Adds language information to the options. | |
LinkBase:: |
protected | function | Checks access to the link route. | |
LinkBase:: |
public static | function | ||
LinkBase:: |
protected | function | Gets the current active user. | |
LinkBase:: |
protected | function | 1 | |
LinkBase:: |
protected | function | ||
LinkBase:: |
protected | function |
Returns the entity type identifier. Overrides EntityTranslationRenderTrait:: |
|
LinkBase:: |
protected | function | ||
LinkBase:: |
protected | function |
Returns the language manager. Overrides EntityTranslationRenderTrait:: |
|
LinkBase:: |
protected | function |
Returns the top object of a view. Overrides EntityTranslationRenderTrait:: |
|
LinkBase:: |
public | function | ||
LinkBase:: |
public | function | 1 | |
LinkBase:: |
public | function | ||
LinkBase:: |
public | function | Constructs a LinkBase object. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. |