You are here

public function FormEntryTypeBase::getAsFlagLink in Flag 8.4

Get the action link formatted for use in entity links.

Parameters

\Drupal\flag\FlagInterface $flag: The flag entity.

\Drupal\Core\Entity\EntityInterface $entity: The flaggable entity.

Return value

array The render array.

Overrides ActionLinkTypeBase::getAsFlagLink

File

src/Plugin/ActionLink/FormEntryTypeBase.php, line 132

Class

FormEntryTypeBase
Base class for link types using form entry.

Namespace

Drupal\flag\Plugin\ActionLink

Code

public function getAsFlagLink(FlagInterface $flag, EntityInterface $entity) {
  $render = parent::getAsFlagLink($flag, $entity);
  if ($this->configuration['form_behavior'] !== 'default') {
    $render['#attached']['library'][] = 'core/drupal.ajax';
    $render['#attributes']['class'][] = 'use-ajax';
    $render['#attributes']['data-dialog-type'] = $this->configuration['form_behavior'];
    $render['#attributes']['data-dialog-options'] = Json::encode([
      'width' => 'auto',
    ]);
  }
  return $render;
}