You are here

public function Popup::execute in Entity Legal 4.0.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/EntityLegal/Popup.php \Drupal\entity_legal\Plugin\EntityLegal\Popup::execute()
  2. 3.0.x src/Plugin/EntityLegal/Popup.php \Drupal\entity_legal\Plugin\EntityLegal\Popup::execute()

Execute callback for Entity Legal method plugin.

Parameters

array $context: Contextual information for plugin to execute on.

Overrides EntityLegalPluginInterface::execute

File

src/Plugin/EntityLegal/Popup.php, line 21

Class

Popup
Method class for alerting existing users via a jQuery UI popup window.

Namespace

Drupal\entity_legal\Plugin\EntityLegal

Code

public function execute(array &$context = []) {
  if (!empty($this->documents)) {

    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = \Drupal::service('renderer');
    $view_builder = \Drupal::entityTypeManager()
      ->getViewBuilder(ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME);

    /** @var \Drupal\entity_legal\EntityLegalDocumentInterface $document */
    foreach ($this->documents as $document) {
      $context['attachments']['#cache']['tags'][] = "entity_legal_document:{$document->id()}";
      $document_markup = $view_builder
        ->view($document
        ->getPublishedVersion());
      $context['attachments']['#attached']['library'][] = 'entity_legal/popup';
      $context['attachments']['#attached']['drupalSettings']['entityLegalPopup'] = [
        [
          'popupTitle' => $document
            ->getPublishedVersion()
            ->label(),
          'popupContent' => $renderer
            ->renderPlain($document_markup),
        ],
      ];
    }
  }
}