By amateescu on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
10.3.x
Introduced in version:
10.3.0
Description:
Drupal core provides two helper interfaces and a trait for marking forms as being safe to submit inside a workspace:
\Drupal\Core\Form\WorkspaceSafeFormInterface\Drupal\Core\Form\WorkspaceDynamicSafeFormInterface\Drupal\Core\Entity\Form\WorkspaceSafeFormTrait
Example implementation for simple forms that can always be marked as workspace-safe:
class SimpleForm extends FormBase implements WorkspaceSafeFormInterface {
...
}
Example implementation for more complex forms that need to determine whether they are workspace-safe based various criteria:
class ComplexForm extends FormBase implements WorkspaceDynamicSafeFormInterface {
use WorkspaceSafeFormTrait;
public function isWorkspaceSafeForm(array $form, FormStateInterface $form_state): bool {
// Use one of the trait methods to determine whether an entity
// or an entity type is workspace-safe.
return $this->isWorkspaceSafeEntityType($this->entityType);
}
}
Impacts:
Module developers