protected function TagForm::copyFormValuesToEntity in Extensible BBCode 8.3
Same name and namespace in other branches
- 4.0.x src/Form/TagForm.php \Drupal\xbbcode\Form\TagForm::copyFormValuesToEntity()
Copies top-level form values to entity properties
This should not change existing entity properties that are not being edited by this form.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity the current form should operate upon.
array $form: A nested array of form elements comprising the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides TagFormBase::copyFormValuesToEntity
File
- src/
Form/ TagForm.php, line 107
Class
- TagForm
- Base form for creating and editing custom tags.
Namespace
Drupal\xbbcode\FormCode
protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) : void {
parent::copyFormValuesToEntity($entity, $form, $form_state);
/** @var \Drupal\xbbcode\Entity\TagInterface $entity */
$name = $entity
->getName();
// Ensure the input is safe for regex patterns, as it is not yet validated.
if (!preg_match('/^\\w+$/', $name)) {
return;
}
// Reverse replacement of the tag name.
$expression = '/(\\[\\/?)' . $name . '([\\s\\]=])/';
$replace = '\\1{{ name }}\\2';
$sample = preg_replace($expression, $replace, $form_state
->getValue('sample'));
$entity
->set('sample', $sample);
}