Wizard.php in Flexiform 8
File
contrib/wizard/src/Entity/Wizard.php
View source
<?php
namespace Drupal\flexiform_wizard\Entity;
use Drupal\Component\Plugin\Context\ContextInterface;
use Drupal\Core\Condition\ConditionPluginCollection;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
class Wizard extends ConfigEntityBase implements EntityWithPluginCollectionInterface {
protected $id;
protected $label;
protected $description;
protected $path;
protected $access_conditions = [];
protected $access_logic = 'and';
protected $accessConditionCollection;
protected $use_admin_theme;
protected $parameters = [];
protected $contexts = [];
protected $pages = [];
public function getDescription() {
return $this->description;
}
public function getPath() {
return $this->path;
}
public function usesAdminTheme() {
return isset($this->use_admin_theme) ? $this->use_admin_theme : strpos($this
->getPath(), '/admin/') === 0;
}
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
static::routeBuilder()
->setRebuildNeeded();
}
public static function postDelete(EntityStorageInterface $storage, array $entities) {
parent::postDelete($storage, $entities);
static::routeBuilder()
->setRebuildNeeded();
}
protected static function routeBuilder() {
return \Drupal::service('router.builder');
}
public function getPluginCollections() {
return [
'access_conditions' => $this
->getAccessConditions(),
];
}
public function getAccessConditions() {
if (!$this->accessConditionCollection) {
$this->accessConditionCollection = new ConditionPluginCollection(\Drupal::service('plugin.manager.condition'), $this
->get('access_conditions'));
}
return $this->accessConditionCollection;
}
public function addAccessCondition(array $configuration) {
$configuration['uuid'] = $this
->uuidGenerator()
->generate();
$this
->getAccessConditions()
->addInstanceId($configuration['uuid'], $configuration);
return $configuration['uuid'];
}
public function getAccessCondition($condition_id) {
return $this
->getAccessConditions()
->get($condition_id);
}
public function removeAccessCondition($condition_id) {
$this
->getAccessConditions()
->removeInstanceId($condition_id);
return $this;
}
public function getAccessLogic() {
return $this->access_logic;
}
public function getParameters() {
$names = $this
->getParameterNames();
if ($names) {
return array_intersect_key($this->parameters, array_flip($names));
}
return [];
}
public function getParameter($name) {
if ($this
->hasParameter($name)) {
return $this->parameters[$name];
}
return NULL;
}
public function hasParameter($name) {
return isset($this->parameters[$name]);
}
public function setParameter($name, $type, $label = '') {
$this->parameters[$name] = [
'machine_name' => $name,
'type' => $type,
'label' => $label,
];
$this->contexts = [];
return $this;
}
public function removeParameter($name) {
unset($this->parameters[$name]);
$this->contexts = [];
return $this;
}
public function getParameterNames() {
if (preg_match_all('|\\{(\\w+)\\}|', $this
->getPath(), $matches)) {
return $matches[1];
}
return [];
}
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);
$this
->filterParameters();
}
protected function filterParameters() {
$names = $this
->getParameterNames();
foreach ($this
->get('parameters') as $name => $parameter) {
if (empty($parameter['type']) || !in_array($name, $names)) {
$this
->removeParameter($name);
}
}
return $this;
}
public function addContext($name, ContextInterface $value) {
$this->contexts[$name] = $value;
}
public function getContexts() {
return $this->contexts;
}
public function getPages() {
return $this->pages;
}
public function __sleep() {
$vars = parent::__sleep();
if (($key = array_search('contexts', $vars)) !== FALSE) {
unset($vars[$key]);
}
return $vars;
}
}
Classes
Name |
Description |
Wizard |
Defines a flexiform wizard entity class. |