SelectionPluginBase.php in Drupal 8
File
core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginBase.php
View source
<?php
namespace Drupal\Core\Entity\EntityReferenceSelection;
use Drupal\Component\Plugin\ConfigurableInterface;
use Drupal\Component\Plugin\ConfigurablePluginInterface;
use Drupal\Component\Plugin\DependentPluginInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginBase;
abstract class SelectionPluginBase extends PluginBase implements SelectionInterface, ConfigurableInterface, DependentPluginInterface, ConfigurablePluginInterface {
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this
->setConfiguration($configuration);
}
public function defaultConfiguration() {
return [
'target_type' => NULL,
'handler' => $this
->getPluginId(),
'entity' => NULL,
];
}
public function getConfiguration() {
return $this->configuration;
}
public function setConfiguration(array $configuration) {
$this
->resolveBackwardCompatibilityConfiguration($configuration);
$this->configuration = NestedArray::mergeDeep($this
->defaultConfiguration(), $configuration);
$this
->ensureBackwardCompatibilityConfiguration();
}
public function calculateDependencies() {
return [];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function entityQueryAlter(SelectInterface $query) {
}
protected function resolveBackwardCompatibilityConfiguration(array &$configuration) {
if (isset($this
->defaultConfiguration()['handler_settings'])) {
throw new \InvalidArgumentException("{$this->getPluginDefinition()['class']}::defaultConfiguration() should not contain a 'handler_settings' key. All settings should be placed in the root level.");
}
if (array_key_exists('handler_settings', $configuration)) {
if (!is_array($configuration['handler_settings'])) {
throw new \InvalidArgumentException("The setting 'handler_settings' is reserved and cannot be used.");
}
@trigger_error("Providing settings under 'handler_settings' is deprecated in drupal:8.4.0 support for 'handler_settings' is removed from drupal:9.0.0. Move the settings in the root of the configuration array. See https://www.drupal.org/node/2870971", E_USER_DEPRECATED);
$configuration += $configuration['handler_settings'];
unset($configuration['handler_settings']);
}
}
protected function ensureBackwardCompatibilityConfiguration() {
$keys = [
'handler',
'target_type',
'entity',
'handler_settings',
];
foreach ($this->configuration as $key => $value) {
if (!in_array($key, $keys, TRUE)) {
$this->configuration['handler_settings'][$key] = $value;
}
}
}
}