public function TagFormCopy::setEntity in Extensible BBCode 8.3
Same name and namespace in other branches
- 4.0.x src/Form/TagFormCopy.php \Drupal\xbbcode\Form\TagFormCopy::setEntity()
Sets the form entity.
Sets the form entity which will be used for populating form element defaults. Usually, the form entity gets updated by \Drupal\Core\Entity\EntityFormInterface::submit(), however this may be used to completely exchange the form entity, e.g. when preparing the rebuild of a multi-step form.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity the current form should operate upon.
Return value
$this
Overrides EntityForm::setEntity
File
- src/
Form/ TagFormCopy.php, line 15
Class
- TagFormCopy
- Form for creating a copy of a BBCode tag.
Namespace
Drupal\xbbcode\FormCode
public function setEntity(EntityInterface $entity) {
// Relabel the entity with a sequential number.
$label = $entity
->label();
if (preg_match('/^(.*?)\\s*(\\d+)$/', $label, $match)) {
[
,
$label,
$number,
] = $match;
}
else {
$number = 1;
}
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $copy */
$copy = $entity
->createDuplicate();
$copy
->set('label', $label . ' ' . ($number + 1));
parent::setEntity($copy);
}