class IFrame in Entity Browser 8
Same name and namespace in other branches
- 8.2 src/Plugin/EntityBrowser/Display/IFrame.php \Drupal\entity_browser\Plugin\EntityBrowser\Display\IFrame
Presents entity browser in an iFrame.
Plugin annotation
@EntityBrowserDisplay(
id = "iframe",
label = @Translation("iFrame"),
description = @Translation("Displays the entity browser in an iFrame container embedded into the main page."),
uses_route = TRUE
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\entity_browser\DisplayBase implements ContainerFactoryPluginInterface, DisplayInterface uses PluginConfigurationFormTrait
- class \Drupal\entity_browser\Plugin\EntityBrowser\Display\IFrame implements DisplayRouterInterface
- class \Drupal\entity_browser\DisplayBase implements ContainerFactoryPluginInterface, DisplayInterface uses PluginConfigurationFormTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of IFrame
File
- src/
Plugin/ EntityBrowser/ Display/ IFrame.php, line 34
Namespace
Drupal\entity_browser\Plugin\EntityBrowser\DisplayView source
class IFrame extends DisplayBase implements DisplayRouterInterface {
/**
* Current route match service.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $currentRouteMatch;
/**
* Current path.
*
* @var \Drupal\Core\Path\CurrentPathStack
*/
protected $currentPath;
/**
* Current request.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* The bare HTML page renderer.
*
* @var \Drupal\Core\Render\BareHtmlPageRendererInterface
*/
protected $bareHtmlPageRenderer;
/**
* Constructs display plugin.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* Event dispatcher service.
* @param \Drupal\Component\Uuid\UuidInterface $uuid
* UUID generator interface.
* @param \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $selection_storage
* The selection storage.
* @param \Drupal\Core\Routing\RouteMatchInterface $current_route_match
* The currently active route match object.
* @param \Symfony\Component\HttpFoundation\Request $request
* Current request.
* @param \Drupal\Core\Path\CurrentPathStack $current_path
* The current path.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
* @param \Drupal\Core\Render\BareHtmlPageRendererInterface $bare_html_page_renderer
* The bare HTML page renderer.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EventDispatcherInterface $event_dispatcher, UuidInterface $uuid, KeyValueStoreExpirableInterface $selection_storage, RouteMatchInterface $current_route_match, Request $request, CurrentPathStack $current_path, RendererInterface $renderer, BareHtmlPageRendererInterface $bare_html_page_renderer) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $event_dispatcher, $uuid, $selection_storage);
$this->currentRouteMatch = $current_route_match;
$this->request = $request;
$this->currentPath = $current_path;
$this->renderer = $renderer;
$this->bareHtmlPageRenderer = $bare_html_page_renderer;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('event_dispatcher'), $container
->get('uuid'), $container
->get('entity_browser.selection_storage'), $container
->get('current_route_match'), $container
->get('request_stack')
->getCurrentRequest(), $container
->get('path.current'), $container
->get('renderer'), $container
->get('bare_html_page_renderer'));
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'width' => '650',
'height' => '500',
'link_text' => $this
->t('Select entities'),
'auto_open' => FALSE,
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function displayEntityBrowser(array $element, FormStateInterface $form_state, array &$complete_form, array $persistent_data = []) {
parent::displayEntityBrowser($element, $form_state, $complete_form, $persistent_data);
/** @var \Drupal\entity_browser\Events\RegisterJSCallbacks $event */
$js_event_object = new RegisterJSCallbacks($this->configuration['entity_browser_id'], $this
->getUuid());
$js_event_object
->registerCallback('Drupal.entityBrowser.selectionCompleted');
$callback_event = $this->eventDispatcher
->dispatch(Events::REGISTER_JS_CALLBACKS, $js_event_object);
$original_path = $this->currentPath
->getPath();
$data = [
'query_parameters' => [
'query' => [
'uuid' => $this
->getUuid(),
'original_path' => $original_path,
],
],
'attributes' => [
'href' => '#browser',
'class' => [
'entity-browser-handle',
'entity-browser-iframe',
],
'data-uuid' => $this
->getUuid(),
'data-original-path' => $original_path,
],
];
$event_object = new AlterEntityBrowserDisplayData($this->configuration['entity_browser_id'], $this
->getUuid(), $this
->getPluginDefinition(), $form_state, $data);
$event = $this->eventDispatcher
->dispatch(Events::ALTER_BROWSER_DISPLAY_DATA, $event_object);
$data = $event
->getData();
return [
'#theme_wrappers' => [
'container',
],
'#attributes' => [
'class' => [
'entity-browser-iframe-container',
],
],
'link' => [
'#type' => 'html_tag',
'#tag' => 'a',
'#value' => $this->configuration['link_text'],
'#attributes' => $data['attributes'],
'#attached' => [
'library' => [
'entity_browser/iframe',
],
'drupalSettings' => [
'entity_browser' => [
$this
->getUuid() => [
'auto_open' => $this->configuration['auto_open'],
],
'iframe' => [
$this
->getUuid() => [
'src' => Url::fromRoute('entity_browser.' . $this->configuration['entity_browser_id'], [], $data['query_parameters'])
->toString(),
'width' => $this->configuration['width'],
'height' => $this->configuration['height'],
'js_callbacks' => $callback_event
->getCallbacks(),
'entity_browser_id' => $this->configuration['entity_browser_id'],
'auto_open' => $this->configuration['auto_open'],
],
],
],
],
],
],
];
}
/**
* KernelEvents::RESPONSE listener.
*
* Intercepts default response and injects response that will trigger JS to
* propagate selected entities upstream.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* Response event.
*/
public function propagateSelection(FilterResponseEvent $event) {
$render = [
'#attached' => [
'library' => [
'entity_browser/' . $this->pluginDefinition['id'] . '_selection',
],
'drupalSettings' => [
'entity_browser' => [
$this->pluginDefinition['id'] => [
'entities' => array_map(function (EntityInterface $item) {
return [
$item
->id(),
$item
->uuid(),
$item
->getEntityTypeId(),
];
}, $this->entities),
'uuid' => $this->request->query
->get('uuid'),
],
],
],
],
];
$event
->setResponse($this->bareHtmlPageRenderer
->renderBarePage($render, $this
->t('Entity browser'), 'page'));
}
/**
* {@inheritdoc}
*/
public function path() {
return '/entity-browser/' . $this->pluginDefinition['id'] . '/' . $this->configuration['entity_browser_id'];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$configuration = $this
->getConfiguration();
$form['width'] = [
'#type' => 'textfield',
'#title' => $this
->t('Width of the iFrame'),
'#default_value' => $configuration['width'],
'#description' => $this
->t('Positive integer for absolute size or a relative size in percentages.'),
];
$form['height'] = [
'#type' => 'number',
'#title' => $this
->t('Height of the iFrame'),
'#min' => 1,
'#default_value' => $configuration['height'],
];
$form['link_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('Link text'),
'#default_value' => $configuration['link_text'],
];
$form['auto_open'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Auto open entity browser'),
'#default_value' => $configuration['auto_open'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
// We want all positive integers, or percentages between 1% and 100%.
$pattern = '/^([1-9][0-9]*|([2-9][0-9]{0,1}%)|(1[0-9]{0,2}%))$/';
if (preg_match($pattern, $form_state
->getValue('width')) == 0) {
$form_state
->setError($form['width'], $this
->t('Width must be a number greater than 0, or a percentage between 1% and 100%.'));
}
if ($form_state
->getValue('height') <= 0) {
$form_state
->setError($form['height'], $this
->t('Height must be greater than 0.'));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DisplayBase:: |
protected | property | Selected entities. | |
DisplayBase:: |
protected | property | Event dispatcher service. | |
DisplayBase:: |
protected | property | Plugin label. | |
DisplayBase:: |
protected | property | The selection storage. | |
DisplayBase:: |
protected | property | Instance UUID string. | |
DisplayBase:: |
protected | property | UUID generator interface. | |
DisplayBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
DisplayBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
DisplayBase:: |
public | function |
Gets the uuid for this display. Overrides DisplayInterface:: |
|
DisplayBase:: |
public | function |
Returns the display label. Overrides DisplayInterface:: |
|
DisplayBase:: |
public | function |
Indicates completed selection. Overrides DisplayInterface:: |
1 |
DisplayBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
DisplayBase:: |
public | function |
Sets the uuid for this display. Overrides DisplayInterface:: |
|
IFrame:: |
protected | property | The bare HTML page renderer. | |
IFrame:: |
protected | property | Current path. | |
IFrame:: |
protected | property | Current route match service. | |
IFrame:: |
protected | property | The renderer service. | |
IFrame:: |
protected | property | Current request. | |
IFrame:: |
public | function |
Implements PluginFormInterface::buildConfigurationForm(). Overrides PluginConfigurationFormTrait:: |
1 |
IFrame:: |
public static | function |
Creates an instance of the plugin. Overrides DisplayBase:: |
|
IFrame:: |
public | function |
Gets default configuration for this plugin. Overrides DisplayBase:: |
|
IFrame:: |
public | function |
Displays entity browser. Overrides DisplayBase:: |
1 |
IFrame:: |
public | function |
Gets page path. Overrides DisplayRouterInterface:: |
|
IFrame:: |
public | function | KernelEvents::RESPONSE listener. | |
IFrame:: |
public | function |
Implements PluginFormInterface::validateConfigurationForm(). Overrides PluginConfigurationFormTrait:: |
1 |
IFrame:: |
public | function |
Constructs display plugin. Overrides DisplayBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginConfigurationFormTrait:: |
public | function | Implements PluginFormInterface::submitConfigurationForm(). | 3 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |