Same name and namespace in other branches
  1. 8.9.x core/modules/contact/src/Plugin/views/field/ContactLink.php \Drupal\contact\Plugin\views\field\ContactLink
  2. 9 core/modules/contact/src/Plugin/views/field/ContactLink.php \Drupal\contact\Plugin\views\field\ContactLink

Hierarchy

Expanded class hierarchy of ContactLink

1 file declares its use of ContactLink
ContactLinkTest.php in core/modules/contact/tests/src/Unit/ContactLinkTest.php

File

core/modules/contact/src/Plugin/views/field/ContactLink.php, line 17

Namespace

Drupal\contact\Plugin\views\field
View 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) {
    $entity = $this
      ->getEntity($row);
    if (!$entity) {
      return NULL;
    }
    return Url::fromRoute('entity.user.contact_form', [
      'user' => $entity
        ->id(),
    ]);
  }

  /**
   * {@inheritdoc}
   */
  protected function renderLink(ResultRow $row) {
    $entity = $this
      ->getEntity($row);
    if (!$entity) {
      return '';
    }
    $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

Namesort descending Modifiers Type Description Overrides
ContactLink::buildOptionsForm public function Overrides LinkBase::buildOptionsForm
ContactLink::getDefaultLabel protected function Returns the default label for this link. Overrides LinkBase::getDefaultLabel
ContactLink::getUrlInfo protected function Returns the URI elements of the link. Overrides LinkBase::getUrlInfo
ContactLink::renderLink protected function Prepares the link to view an entity. Overrides LinkBase::renderLink
EntityTranslationRenderTrait::$entityTranslationRenderer protected property The renderer to be used to render the entity row.
EntityTranslationRenderTrait::getEntityTranslation Deprecated public function Returns the entity translation matching the configured row language.
EntityTranslationRenderTrait::getEntityTranslationByRelationship public function Returns the entity translation matching the configured row language.
EntityTranslationRenderTrait::getEntityTranslationRenderer protected function Returns the current renderer.
LinkBase::$accessManager protected property The access manager service.
LinkBase::$currentUser protected property Current user object.
LinkBase::$entityRepository protected property The entity repository.
LinkBase::$entityTypeManager protected property The entity type manager.
LinkBase::$languageManager protected property The language manager.
LinkBase::addLangcode protected function Adds language information to the options.
LinkBase::checkUrlAccess protected function Checks access to the link route.
LinkBase::create public static function
LinkBase::currentUser protected function Gets the current active user.
LinkBase::defineOptions protected function 1
LinkBase::getEntityRepository protected function
LinkBase::getEntityTypeId protected function Returns the entity type identifier. Overrides EntityTranslationRenderTrait::getEntityTypeId
LinkBase::getEntityTypeManager protected function
LinkBase::getLanguageManager protected function Returns the language manager. Overrides EntityTranslationRenderTrait::getLanguageManager
LinkBase::getView protected function Returns the top object of a view. Overrides EntityTranslationRenderTrait::getView
LinkBase::query public function
LinkBase::render public function 1
LinkBase::usesGroupBy public function
LinkBase::__construct public function Constructs a LinkBase object.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.