function WorkspaceSafeFormTrait::isWorkspaceSafeForm

Determines whether the current form is safe to be submitted in a workspace.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

bool TRUE if the form is workspace-safe, FALSE otherwise.

File

core/modules/layout_builder/src/Form/WorkspaceSafeFormTrait.php, line 29

Class

WorkspaceSafeFormTrait
Provides a trait that marks Layout Builder forms as workspace-safe.

Namespace

Drupal\layout_builder\Form

Code

public function isWorkspaceSafeForm(array $form, FormStateInterface $form_state) : bool {
    $section_storage = $this->sectionStorage ?: $this->getSectionStorageFromFormState($form_state);
    if ($section_storage) {
        $context_definitions = $section_storage->getContextDefinitions();
        if (!empty($context_definitions['entity'])) {
            
            /** @var \Drupal\Core\Entity\EntityInterface $entity */
            $entity = $section_storage->getContextValue('entity');
            return $this->isWorkspaceSafeEntity($entity);
        }
    }
    return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.