class View in Entity Browser 8
Same name in this branch
- 8 src/Plugin/EntityBrowser/Widget/View.php \Drupal\entity_browser\Plugin\EntityBrowser\Widget\View
- 8 src/Plugin/EntityBrowser/SelectionDisplay/View.php \Drupal\entity_browser\Plugin\EntityBrowser\SelectionDisplay\View
Same name and namespace in other branches
- 8.2 src/Plugin/EntityBrowser/SelectionDisplay/View.php \Drupal\entity_browser\Plugin\EntityBrowser\SelectionDisplay\View
Displays current selection in a View.
Plugin annotation
@EntityBrowserSelectionDisplay(
id = "view",
label = @Translation("View selection display"),
description = @Translation("Use a pre-configured view as selection area."),
acceptPreselection = TRUE,
provider = "views",
js_commands = FALSE
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\entity_browser\SelectionDisplayBase implements ContainerFactoryPluginInterface, SelectionDisplayInterface uses PluginConfigurationFormTrait
- class \Drupal\entity_browser\Plugin\EntityBrowser\SelectionDisplay\View
- class \Drupal\entity_browser\SelectionDisplayBase implements ContainerFactoryPluginInterface, SelectionDisplayInterface uses PluginConfigurationFormTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of View
File
- src/
Plugin/ EntityBrowser/ SelectionDisplay/ View.php, line 23
Namespace
Drupal\entity_browser\Plugin\EntityBrowser\SelectionDisplayView source
class View extends SelectionDisplayBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'view' => NULL,
'view_display' => NULL,
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function getForm(array &$original_form, FormStateInterface $form_state) {
$form = [];
// TODO - do we need better error handling for view and view_display
// (in case either of those is nonexistent
// or display not of correct type)?
$storage =& $form_state
->getStorage();
if (empty($storage['selection_display_view']) || $form_state
->isRebuilding()) {
$storage['selection_display_view'] = $this->entityTypeManager
->getStorage('view')
->load($this->configuration['view'])
->getExecutable();
}
// TODO - if there are entities that are selected multiple times this
// displays them only once. Reason for that is how SQL and Views work and
// we probably can't do much about it.
$selected_entities = $form_state
->get([
'entity_browser',
'selected_entities',
]);
if (!empty($selected_entities)) {
$ids = array_map(function (EntityInterface $item) {
return $item
->id();
}, $selected_entities);
$storage['selection_display_view']
->setArguments([
implode(',', $ids),
]);
}
$form['view'] = $storage['selection_display_view']
->executeDisplay($this->configuration['view_display']);
$form['use_selected'] = [
'#type' => 'submit',
'#value' => $this
->t('Use selection'),
'#name' => 'use_selected',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submit(array &$form, FormStateInterface $form_state) {
if ($form_state
->getTriggeringElement()['#name'] == 'use_selected') {
$this
->selectionDone($form_state);
}
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$options = [];
// Get all views displays.
$views = Views::getAllViews();
foreach ($views as $view_id => $view) {
foreach ($view
->get('display') as $display_id => $display) {
$options[$view_id . '.' . $display_id] = $this
->t('@view : @display', [
'@view' => $view
->label(),
'@display' => $display['display_title'],
]);
}
}
$form['view'] = [
'#type' => 'select',
'#title' => $this
->t('View : View display'),
'#default_value' => $this->configuration['view'] . '.' . $this->configuration['view_display'],
'#options' => $options,
'#required' => TRUE,
'#description' => $this
->t('View display to use for displaying currently selected items. Do note that to get something useful out of this display, its first contextual filter should be a filter on the primary identifier field of your entity type (e.g., Node ID, Media ID).'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
if (!empty($values['view'])) {
list($view_id, $display_id) = explode('.', $values['view']);
$this->configuration['view'] = $view_id;
$this->configuration['view_display'] = $display_id;
}
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
$dependencies = [];
if ($this->configuration['view']) {
$view = ViewEntity::load($this->configuration['view']);
$dependencies[$view
->getConfigDependencyKey()] = [
$view
->getConfigDependencyName(),
];
}
return $dependencies;
}
}
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 | |
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::validateConfigurationForm(). | 2 |
SelectionDisplayBase:: |
protected | property | Entity manager service. | |
SelectionDisplayBase:: |
protected | property | Event dispatcher service. | |
SelectionDisplayBase:: |
protected | property | Plugin label. | |
SelectionDisplayBase:: |
public | function |
Check does selection display support preselection. Overrides SelectionDisplayInterface:: |
|
SelectionDisplayBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
SelectionDisplayBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
SelectionDisplayBase:: |
public | function |
Returns the selection display label. Overrides SelectionDisplayInterface:: |
|
SelectionDisplayBase:: |
protected | function | Marks selection as done - sets value in form state and dispatches event. | |
SelectionDisplayBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
SelectionDisplayBase:: |
public | function |
Returns true if selection display supports selection over javascript. Overrides SelectionDisplayInterface:: |
|
SelectionDisplayBase:: |
public | function |
Check if the plugin supports preselection. Overrides SelectionDisplayInterface:: |
|
SelectionDisplayBase:: |
public | function |
Validates form. Overrides SelectionDisplayInterface:: |
|
SelectionDisplayBase:: |
public | function |
Constructs widget plugin. Overrides PluginBase:: |
1 |
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. | |
View:: |
public | function |
Implements PluginFormInterface::buildConfigurationForm(). Overrides PluginConfigurationFormTrait:: |
|
View:: |
public | function |
Calculates dependencies for the configured plugin. Overrides SelectionDisplayBase:: |
|
View:: |
public | function |
Gets default configuration for this plugin. Overrides SelectionDisplayBase:: |
|
View:: |
public | function |
Returns selection display form. Overrides SelectionDisplayInterface:: |
|
View:: |
public | function |
Submits form. Overrides SelectionDisplayBase:: |
|
View:: |
public | function |
Implements PluginFormInterface::submitConfigurationForm(). Overrides PluginConfigurationFormTrait:: |