View source
<?php
namespace Drupal\yamlform\Entity;
use Drupal\Core\Serialization\Yaml;
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\user\Entity\User;
use Drupal\user\UserInterface;
use Drupal\yamlform\Utility\YamlFormElementHelper;
use Drupal\yamlform\YamlFormHandlerInterface;
use Drupal\yamlform\YamlFormHandlerPluginCollection;
use Drupal\yamlform\YamlFormInterface;
use Drupal\yamlform\YamlFormSubmissionInterface;
class YamlForm extends ConfigEntityBundleBase implements YamlFormInterface {
use StringTranslationTrait;
protected $id;
protected $uuid;
protected $status = TRUE;
protected $template = FALSE;
protected $title;
protected $description;
protected $uid;
protected $settings = [];
protected $access = [];
protected $elements;
protected $css = '';
protected $javascript = '';
protected $handlers = [];
protected $handlersCollection;
protected $elementsOriginal;
protected $elementsDecoded;
protected $elementsInitialized;
protected $elementsDecodedAndFlattened;
protected $elementsInitializedAndFlattened;
protected $elementsFlattenedAndHasValue;
protected $elementsTranslations;
protected $pages;
protected $hasManagedFile = FALSE;
protected $hasFlexboxLayout = FALSE;
protected $hasTranslations;
public function getOwner() {
return $this->uid ? User::load($this->uid) : NULL;
}
public function setOwner(UserInterface $account) {
$this->uid = $account
->id();
return $this;
}
public function getOwnerId() {
return $this->uid;
}
public function setOwnerId($uid) {
$this->uid = $uid ? $uid : NULL;
return $this;
}
public function isOpen() {
return $this->status ? TRUE : FALSE;
}
public function isClosed() {
return !$this
->isOpen();
}
public function isTemplate() {
return $this->template ? TRUE : FALSE;
}
public function isConfidential() {
return $this
->getSetting('form_confidential');
}
public function hasSubmissions() {
$submission_storage = \Drupal::entityTypeManager()
->getStorage('yamlform_submission');
return $submission_storage
->getTotal($this) ? TRUE : FALSE;
}
public function hasTranslations() {
if (isset($this->hasTranslations)) {
return $this->hasTranslations;
}
if (!\Drupal::moduleHandler()
->moduleExists('config_translation')) {
$this->hasTranslations = FALSE;
return $this->hasTranslations;
}
$local_config_manager = \Drupal::service('locale.config_manager');
$languages = \Drupal::languageManager()
->getLanguages();
foreach ($languages as $langcode => $language) {
if ($local_config_manager
->hasTranslation('yamlform.yamlform.' . $this
->id(), $langcode)) {
$this->hasTranslations = TRUE;
return $this->hasTranslations;
}
}
$this->hasTranslations = FALSE;
return $this->hasTranslations;
}
public function hasPage() {
$settings = $this
->getSettings();
return $settings['page'] ? TRUE : FALSE;
}
public function hasManagedFile() {
$this
->initElements();
return $this->hasManagedFile;
}
public function hasFlexboxLayout() {
$this
->initElements();
return $this->hasFlexboxLayout;
}
public function getDescription() {
return $this->description;
}
public function setDescription($description) {
$this->description = $description;
return $this;
}
public function getCss() {
return $this->css;
}
public function setCss($css) {
$this->css = $css;
return $this;
}
public function getJavaScript() {
return $this->javascript;
}
public function setJavaScript($javascript) {
$this->javascript = $javascript;
return $this;
}
public function getSettings() {
return $this->settings + self::getDefaultSettings();
}
public function setSettings(array $settings) {
$this->settings = self::getDefaultSettings();
foreach ($settings as $name => $value) {
$this->settings[$name] = $value;
}
return $this;
}
public function getSetting($key) {
$settings = $this
->getSettings();
return isset($settings[$key]) ? $settings[$key] : NULL;
}
public function setSetting($key, $value) {
$settings = $this
->getSettings();
$settings[$key] = $value;
$this
->setSettings($settings);
return $this;
}
public function getAccessRules() {
return $this->access;
}
public function setAccessRules(array $access) {
$this->access = $access;
return $this;
}
public static function getDefaultSettings() {
return [
'page' => TRUE,
'page_submit_path' => '',
'page_confirm_path' => '',
'form_submit_label' => '',
'form_submit_attributes' => [],
'form_exception_message' => '',
'form_closed_message' => '',
'form_confidential' => FALSE,
'form_confidential_message' => '',
'form_prepopulate' => FALSE,
'form_prepopulate_source_entity' => FALSE,
'form_novalidate' => FALSE,
'form_unsaved' => FALSE,
'form_disable_back' => FALSE,
'form_autofocus' => FALSE,
'form_details_toggle' => FALSE,
'wizard_progress_bar' => TRUE,
'wizard_progress_pages' => FALSE,
'wizard_progress_percentage' => FALSE,
'wizard_next_button_label' => '',
'wizard_next_button_attributes' => [],
'wizard_prev_button_label' => '',
'wizard_prev_button_attributes' => [],
'wizard_start_label' => '',
'wizard_complete' => TRUE,
'wizard_complete_label' => '',
'preview' => DRUPAL_DISABLED,
'preview_next_button_label' => '',
'preview_next_button_attributes' => [],
'preview_prev_button_label' => '',
'preview_prev_button_attributes' => [],
'preview_message' => '',
'draft' => FALSE,
'draft_auto_save' => FALSE,
'draft_button_label' => '',
'draft_button_attributes' => [],
'draft_saved_message' => '',
'draft_loaded_message' => '',
'confirmation_type' => 'page',
'confirmation_message' => '',
'confirmation_url' => '',
'confirmation_attributes' => [],
'confirmation_back' => TRUE,
'confirmation_back_label' => '',
'confirmation_back_attributes' => [],
'limit_total' => NULL,
'limit_total_message' => '',
'limit_user' => NULL,
'limit_user_message' => '',
'entity_limit_total' => NULL,
'entity_limit_user' => NULL,
'results_disabled' => FALSE,
'results_disabled_ignore' => FALSE,
'token_update' => FALSE,
];
}
public static function getDefaultAccessRules() {
return [
'create' => [
'roles' => [
'anonymous',
'authenticated',
],
'users' => [],
],
'view_any' => [
'roles' => [],
'users' => [],
],
'update_any' => [
'roles' => [],
'users' => [],
],
'delete_any' => [
'roles' => [],
'users' => [],
],
'purge_any' => [
'roles' => [],
'users' => [],
],
'view_own' => [
'roles' => [],
'users' => [],
],
'update_own' => [
'roles' => [],
'users' => [],
],
'delete_own' => [
'roles' => [],
'users' => [],
],
];
}
public function checkAccessRules($operation, AccountInterface $account, YamlFormSubmissionInterface $yamlform_submission = NULL) {
if ($account
->hasPermission('administer yamlform') || $account
->hasPermission('administer yamlform submission')) {
return TRUE;
}
if ($operation == 'page') {
if (empty($this->settings['page'])) {
return FALSE;
}
else {
$operation = 'create';
}
}
$access_rules = $this
->getAccessRules();
if (isset($access_rules[$operation]) && in_array($operation, [
'create',
'view_any',
'update_any',
'delete_any',
'purge_any',
'view_own',
]) && $this
->checkAccessRule($access_rules[$operation], $account)) {
return TRUE;
}
elseif (isset($access_rules[$operation . '_any']) && $this
->checkAccessRule($access_rules[$operation . '_any'], $account)) {
return TRUE;
}
elseif (isset($access_rules[$operation . '_own']) && $account
->isAuthenticated() && $yamlform_submission && $account
->id() === $yamlform_submission
->getOwnerId() && $this
->checkAccessRule($access_rules[$operation . '_own'], $account)) {
return TRUE;
}
else {
return FALSE;
}
}
protected function checkAccessRule(array $access_rule, AccountInterface $account) {
if (!empty($access_rule['roles']) && array_intersect($access_rule['roles'], $account
->getRoles())) {
return TRUE;
}
elseif (!empty($access_rule['users']) && in_array($account
->id(), $access_rule['users'])) {
return TRUE;
}
else {
return FALSE;
}
}
public function getSubmissionForm(array $values = [], $operation = 'default') {
$values['yamlform_id'] = $this
->id();
$yamlform_submission = $this
->entityTypeManager()
->getStorage('yamlform_submission')
->create($values);
return \Drupal::service('entity.form_builder')
->getForm($yamlform_submission, $operation);
}
public function getElementsRaw() {
return $this->elements;
}
public function getElementsOriginalRaw() {
return $this->elementsOriginal;
}
public function getElementsDecoded() {
$this
->initElements();
return $this->elementsDecoded;
}
public function getElementsInitialized() {
$this
->initElements();
return $this->elementsInitialized;
}
public function getElementsInitializedAndFlattened() {
$this
->initElements();
return $this->elementsInitializedAndFlattened;
}
public function getElementsDecodedAndFlattened() {
$this
->initElements();
return $this->elementsDecodedAndFlattened;
}
public function getElementsFlattenedAndHasValue() {
$this
->initElements();
return $this->elementsFlattenedAndHasValue;
}
public function getElementsSelectorOptions() {
$element_manager = \Drupal::service('plugin.manager.yamlform.element');
$selectors = [];
$elements = $this
->getElementsInitializedAndFlattened();
foreach ($elements as $element) {
$element_handler = $element_manager
->getElementInstance($element);
$selectors += $element_handler
->getElementSelectorOptions($element);
}
return $selectors;
}
public function setElements(array $elements) {
$this->elements = Yaml::encode($elements);
$this
->resetElements();
return $this;
}
protected function initElements() {
if (isset($this->elementsInitialized)) {
return;
}
$this->elementsDecodedAndFlattened = [];
$this->elementsInitializedAndFlattened = [];
$this->elementsFlattenedAndHasValue = [];
$this->elementsTranslations = [];
try {
$translation_manager = \Drupal::service('yamlform.translation_manager');
$language_manager = \Drupal::service('language_manager');
if ($this->langcode != $language_manager
->getCurrentLanguage()
->getId()) {
$default_langcode = $language_manager
->getDefaultLanguage()
->getId();
$elements = $translation_manager
->getConfigElements($this, $default_langcode);
$this->elementsTranslations = Yaml::decode($this->elements);
}
else {
$elements = Yaml::decode($this->elements);
}
$elements = is_array($elements) ? $elements : [];
$this->elementsDecoded = $elements;
} catch (\Exception $exception) {
$link = $this
->link(t('Edit'), 'edit-form');
\Drupal::logger('yamlform')
->notice('%title elements are not valid. @message', [
'%title' => $this
->label(),
'@message' => $exception
->getMessage(),
'link' => $link,
]);
$elements = FALSE;
}
if ($elements !== FALSE) {
$this
->initElementsRecursive($elements);
$this
->invokeHandlers('alterElements', $elements, $this);
}
$this->elementsInitialized = $elements;
}
protected function resetElements() {
$this->elementsDecoded = NULL;
$this->elementsInitialized = NULL;
$this->elementsDecodedAndFlattened = NULL;
$this->elementsInitializedAndFlattened = NULL;
$this->elementsFlattenedAndHasValue = NULL;
$this->elementsTranslations = NULL;
}
protected function initElementsRecursive(array &$elements, $parent = '', $depth = 0) {
$element_manager = \Drupal::service('plugin.manager.yamlform.element');
$element_info = \Drupal::service('plugin.manager.element_info');
$elements = YamlFormElementHelper::removeIgnoredProperties($elements);
foreach ($elements as $key => &$element) {
if (Element::property($key) || !is_array($element)) {
continue;
}
if (isset($this->elementsTranslations[$key])) {
YamlFormElementHelper::applyTranslation($element, $this->elementsTranslations[$key]);
}
$this->elementsDecodedAndFlattened[$key] = YamlFormElementHelper::getProperties($element);
$element['#yamlform_id'] = $this
->id() . '--' . $key;
$element['#yamlform_key'] = $key;
$element['#yamlform_parent_key'] = $parent;
$element['#yamlform_parent_flexbox'] = FALSE;
$element['#yamlform_depth'] = $depth;
$element['#yamlform_children'] = [];
$element['#yamlform_multiple'] = FALSE;
$element['#yamlform_composite'] = FALSE;
if (!empty($parent)) {
$parent_element = $this->elementsInitializedAndFlattened[$parent];
$parent_element['#yamlform_children'][$key] = $key;
$element['#yamlform_parent_flexbox'] = isset($parent_element['#type']) && $parent_element['#type'] == 'yamlform_flexbox' ? TRUE : FALSE;
}
$element += [
'#title' => NULL,
'#admin_title' => NULL,
];
if (!empty($element['#private'])) {
$element['#access'] = $this
->access('submission_view_any');
}
$element_handler = NULL;
if (isset($element['#type'])) {
if ($element['#type'] == 'managed_file') {
$this->hasManagedFile = TRUE;
}
if ($element['#type'] == 'flexbox' || $element['#type'] == 'yamlform_flexbox') {
$this->hasFlexboxLayout = TRUE;
}
if (!$element_info
->hasDefinition($element['#type']) && $element_info
->hasDefinition('yamlform_' . $element['#type'])) {
$element['#type'] = 'yamlform_' . $element['#type'];
}
$element_handler = $element_manager
->createInstance($element['#type']);
$element_handler
->initialize($element);
$element['#yamlform_multiple'] = $element_handler
->hasMultipleValues($element);
$element['#yamlform_composite'] = $element_handler
->isComposite();
}
$this->elementsInitializedAndFlattened[$key] = YamlFormElementHelper::getProperties($element);
if ($element_handler && $element_handler
->isInput($element)) {
$this->elementsFlattenedAndHasValue[$key] =& $this->elementsInitializedAndFlattened[$key];
}
$this
->initElementsRecursive($element, $key, $depth + 1);
}
}
public function getElement($key) {
$elements_flattened = $this
->getElementsInitializedAndFlattened();
return isset($elements_flattened[$key]) ? $elements_flattened[$key] : NULL;
}
public function getElementDecoded($key) {
$elements = $this
->getElementsDecodedAndFlattened();
return isset($elements[$key]) ? $elements[$key] : NULL;
}
public function getElementInitialized($key) {
$elements = $this
->getElementsInitializedAndFlattened();
return isset($elements[$key]) ? $elements[$key] : NULL;
}
public function setElementProperties($key, array $properties, $parent_key = '') {
$elements = $this
->getElementsDecoded();
if (!$this
->setElementPropertiesRecursive($elements, $key, $properties, $parent_key)) {
$elements[$key] = $properties;
}
$this
->setElements($elements);
return $this;
}
protected function setElementPropertiesRecursive(array &$elements, $key, array $properties, $parent_key = '') {
foreach ($elements as $element_key => &$element) {
if (Element::property($element_key) || !is_array($element)) {
continue;
}
if ($element_key == $key) {
$element = $properties + YamlFormElementHelper::removeProperties($element);
return TRUE;
}
if ($element_key == $parent_key) {
$element[$key] = $properties;
return TRUE;
}
if ($this
->setElementPropertiesRecursive($element, $key, $properties, $parent_key)) {
return TRUE;
}
}
return FALSE;
}
public function deleteElement($key) {
$elements = $this
->getElementsDecoded();
$sub_element_keys = $this
->deleteElementRecursive($elements, $key);
$this
->setElements($elements);
\Drupal::database()
->delete('yamlform_submission_data')
->condition('yamlform_id', $this
->id())
->condition('name', $sub_element_keys, 'IN')
->execute();
}
protected function deleteElementRecursive(array &$elements, $key) {
foreach ($elements as $element_key => &$element) {
if (Element::property($element_key) || !is_array($element)) {
continue;
}
if ($element_key == $key) {
$sub_element_keys = [
$element_key => $element_key,
];
$this
->collectSubElementKeysRecursive($sub_element_keys, $element);
unset($elements[$element_key]);
return $sub_element_keys;
}
if ($sub_element_keys = $this
->deleteElementRecursive($element, $key)) {
return $sub_element_keys;
}
}
return FALSE;
}
protected function collectSubElementKeysRecursive(array &$sub_element_keys, array $elements) {
foreach ($elements as $key => &$element) {
if (Element::property($key) || !is_array($element)) {
continue;
}
$sub_element_keys[$key] = $key;
$this
->collectSubElementKeysRecursive($sub_element_keys, $element);
}
}
public function getPages() {
if (isset($this->pages)) {
return $this->pages;
}
$wizard_properties = [
'#title' => '#title',
'#prev_button_label' => '#prev_button_label',
'#next_button_label' => '#next_button_label',
];
$elements = $this
->getElementsInitialized();
$this->pages = [];
if (is_array($elements)) {
foreach ($elements as $key => $element) {
if (isset($element['#type']) && $element['#type'] == 'yamlform_wizard_page') {
$this->pages[$key] = array_intersect_key($element, $wizard_properties);
}
}
}
$settings = $this
->getSettings();
if ($settings['preview'] != DRUPAL_DISABLED) {
if (empty($this->pages)) {
$this->pages['start'] = [
'#title' => $this
->getSetting('wizard_start_label') ?: \Drupal::config('yamlform.settings')
->get('settings.default_wizard_start_label'),
];
}
$this->pages['preview'] = [
'#title' => $this
->t('Preview'),
];
}
if ($this->pages && $this
->getSetting('wizard_complete')) {
$this->pages['complete'] = [
'#title' => $this
->getSetting('wizard_complete_label') ?: \Drupal::config('yamlform.settings')
->get('settings.default_wizard_complete_label'),
];
}
return $this->pages;
}
public function getPage($key) {
$pages = $this
->getPages();
return isset($pages[$key]) ? $pages[$key] : NULL;
}
public static function preCreate(EntityStorageInterface $storage, array &$values) {
$values += [
'uid' => \Drupal::currentUser()
->id(),
'settings' => self::getDefaultSettings(),
'access' => self::getDefaultAccessRules(),
];
}
public static function postLoad(EntityStorageInterface $storage, array &$entities) {
foreach ($entities as $entity) {
$entity->elementsOriginal = $entity->elements;
}
}
public static function preDelete(EntityStorageInterface $storage, array $entities) {
parent::preDelete($storage, $entities);
foreach ($entities as $entity) {
$entity
->deletePaths();
\Drupal::state()
->delete('yamlform.yamlform.' . $entity
->id());
}
$submission_ids = \Drupal::entityQuery('yamlform_submission')
->condition('yamlform_id', array_keys($entities), 'IN')
->sort('sid')
->execute();
$submission_storage = \Drupal::entityTypeManager()
->getStorage('yamlform_submission');
$submissions = $submission_storage
->loadMultiple($submission_ids);
$submission_storage
->delete($submissions);
}
public function getCacheTags() {
$cache_tags = parent::getCacheTags();
$cache_tags[] = 'yamlform:' . $this
->id();
return $cache_tags;
}
public function preSave(EntityStorageInterface $storage) {
if ($this
->isTemplate()) {
$this
->setStatus(FALSE);
}
if (is_array($this->elements)) {
$this->elements = Yaml::encode($this->elements);
}
parent::preSave($storage);
}
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
$this
->updatePaths();
$this
->resetElements();
}
public function updatePaths() {
if (!\Drupal::moduleHandler()
->moduleExists('path')) {
return;
}
$submit_path = $this->settings['page_submit_path'] ?: trim(\Drupal::config('yamlform.settings')
->get('settings.default_page_base_path'), '/') . '/' . str_replace('_', '-', $this
->id());
$submit_source = '/yamlform/' . $this
->id();
$submit_alias = '/' . trim($submit_path, '/');
$this
->updatePath($submit_source, $submit_alias, $this->langcode);
$this
->updatePath($submit_source, $submit_alias, LanguageInterface::LANGCODE_NOT_SPECIFIED);
$confirm_path = $this->settings['page_confirm_path'] ?: $submit_path . '/confirmation';
$confirm_source = '/yamlform/' . $this
->id() . '/confirmation';
$confirm_alias = '/' . trim($confirm_path, '/');
$this
->updatePath($confirm_source, $confirm_alias, $this->langcode);
$this
->updatePath($confirm_source, $confirm_alias, LanguageInterface::LANGCODE_NOT_SPECIFIED);
$submissions_path = $submit_path . '/submissions';
$submissions_source = '/yamlform/' . $this
->id() . '/submissions';
$submissions_alias = '/' . trim($submissions_path, '/');
$this
->updatePath($submissions_source, $submissions_alias, $this->langcode);
$this
->updatePath($submissions_source, $submissions_alias, LanguageInterface::LANGCODE_NOT_SPECIFIED);
}
public function deletePaths() {
$path_alias_storage = \Drupal::service('path.alias_storage');
$path_alias_storage
->delete([
'source' => '/yamlform/' . $this
->id(),
]);
$path_alias_storage
->delete([
'source' => '/yamlform/' . $this
->id() . '/confirmation',
]);
}
protected function updatePath($source, $alias, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED) {
$path_alias_storage = \Drupal::service('path.alias_storage');
$path = $path_alias_storage
->load([
'source' => $source,
'langcode' => $langcode,
]);
if ($path && $path['alias'] == $alias) {
return;
}
$path_alias_storage
->save($source, $alias, $langcode, $path['pid']);
}
public function deleteYamlFormHandler(YamlFormHandlerInterface $handler) {
$this
->getHandlers()
->removeInstanceId($handler
->getHandlerId());
$this
->save();
return $this;
}
protected function getYamlFormHandlerPluginManager() {
return \Drupal::service('plugin.manager.yamlform.handler');
}
public function getHandler($handler) {
return $this
->getHandlers()
->get($handler);
}
public function getHandlers($plugin_id = NULL, $status = NULL, $results = NULL) {
if (!$this->handlersCollection) {
$this->handlersCollection = new YamlFormHandlerPluginCollection($this
->getYamlFormHandlerPluginManager(), $this->handlers);
foreach ($this->handlersCollection as $handler) {
$handler
->init($this);
}
$this->handlersCollection
->sort();
}
$handlers = $this->handlersCollection;
if (isset($plugin_id) || isset($status) || isset($results)) {
$handlers = clone $this->handlersCollection;
}
if (isset($plugin_id)) {
foreach ($handlers as $instance_id => $handler) {
if ($handler
->getPluginId() != $plugin_id) {
$handlers
->removeInstanceId($instance_id);
}
}
}
if (isset($status)) {
foreach ($handlers as $instance_id => $handler) {
if ($handler
->getStatus() != $status) {
$handlers
->removeInstanceId($instance_id);
}
}
}
if (isset($results)) {
foreach ($handlers as $instance_id => $handler) {
$plugin_definition = $handler
->getPluginDefinition();
if ($plugin_definition['results'] != $results) {
$handlers
->removeInstanceId($instance_id);
}
}
}
return $handlers;
}
public function getPluginCollections() {
return [
'handlers' => $this
->getHandlers(),
];
}
public function addYamlFormHandler(array $configuration) {
$this
->getHandlers()
->addInstanceId($configuration['handler_id'], $configuration);
return $configuration['handler_id'];
}
public function invokeHandlers($method, &$data, &$context1 = NULL, &$context2 = NULL) {
$handlers = $this
->getHandlers();
foreach ($handlers as $handler) {
if ($handler
->isEnabled()) {
$handler
->{$method}($data, $context1, $context2);
}
}
}
public function invokeElements($method, &$data, &$context1 = NULL, &$context2 = NULL) {
$element_manager = \Drupal::service('plugin.manager.yamlform.element');
$elements = $this
->getElementsInitializedAndFlattened();
foreach ($elements as $element) {
$element_manager
->invokeMethod($method, $element, $data, $context1, $context2);
}
}
public function url($rel = 'canonical', $options = []) {
return parent::url($rel, $options);
}
public function toUrl($rel = 'canonical', array $options = []) {
return parent::toUrl($rel, $options);
}
public function urlInfo($rel = 'canonical', array $options = []) {
return parent::urlInfo($rel, $options);
}
public function toLink($text = NULL, $rel = 'canonical', array $options = []) {
return parent::toLink($text, $rel, $options);
}
public function link($text = NULL, $rel = 'canonical', array $options = []) {
return parent::link($text, $rel, $options);
}
public function isDefaultRevision() {
return TRUE;
}
public function getState($key, $default = NULL) {
$namespace = 'yamlform.yamlform.' . $this
->id();
$values = \Drupal::state()
->get($namespace, []);
return isset($values[$key]) ? $values[$key] : $default;
}
public function setState($key, $value) {
$namespace = 'yamlform.yamlform.' . $this
->id();
$values = \Drupal::state()
->get($namespace, []);
$values[$key] = $value;
\Drupal::state()
->set($namespace, $values);
}
public function deleteState($key) {
$namespace = 'yamlform.yamlform.' . $this
->id();
$values = \Drupal::state()
->get($namespace, []);
unset($values[$key]);
\Drupal::state()
->set($namespace, $values);
}
public function hasState($key) {
$namespace = 'yamlform.yamlform.' . $this
->id();
$values = \Drupal::state()
->get($namespace, []);
return isset($values[$key]) ? TRUE : FALSE;
}
public function onDependencyRemoval(array $dependencies) {
$changed = parent::onDependencyRemoval($dependencies);
$handlers = $this
->getHandlers();
if (empty($handlers)) {
return $changed;
}
foreach ($handlers as $handler) {
$plugin_definition = $handler
->getPluginDefinition();
$provider = $plugin_definition['provider'];
if (in_array($provider, $dependencies['module'])) {
$this
->deleteYamlFormHandler($handler);
$changed = TRUE;
}
}
return $changed;
}
public function getIterator() {
return new \ArrayIterator([]);
}
}