You are here

class Popup in Entity Legal 8.2

Same name and namespace in other branches
  1. 4.0.x src/Plugin/EntityLegal/Popup.php \Drupal\entity_legal\Plugin\EntityLegal\Popup
  2. 3.0.x src/Plugin/EntityLegal/Popup.php \Drupal\entity_legal\Plugin\EntityLegal\Popup

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

Plugin annotation


@EntityLegal(
  id = "popup",
  label = @Translation("Popup on all pages until accepted"),
  type = "existing_users",
)

Hierarchy

Expanded class hierarchy of Popup

File

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

Namespace

Drupal\entity_legal\Plugin\EntityLegal
View source
class Popup extends EntityLegalPluginBase {

  /**
   * {@inheritdoc}
   */
  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),
          ],
        ];
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityLegalPluginBase::$documents protected property The legal documents that implement this plugin.
EntityLegalPluginBase::getDocumentsForMethod public function Get all Entity Legal Documents for this plugin.
EntityLegalPluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct 1
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
Popup::execute public function Execute callback for Entity Legal method plugin. Overrides EntityLegalPluginInterface::execute