TagFormCopy.php in Extensible BBCode 4.0.x
File
src/Form/TagFormCopy.php
View source
<?php
namespace Drupal\xbbcode\Form;
use Drupal\Core\Entity\EntityInterface;
class TagFormCopy extends TagForm {
public function setEntity(EntityInterface $entity) {
$label = $entity
->label();
if (preg_match('/^(.*?)\\s*(\\d+)$/', $label, $match)) {
[
,
$label,
$number,
] = $match;
}
else {
$number = 1;
}
$copy = $entity
->createDuplicate();
$copy
->set('label', $label . ' ' . ($number + 1));
parent::setEntity($copy);
}
}