public function HierarchyChildrenForm::save in Entity Reference Hierarchy 3.x
Same name and namespace in other branches
- 8.2 src/Form/HierarchyChildrenForm.php \Drupal\entity_hierarchy\Form\HierarchyChildrenForm::save()
Form submission handler for the 'save' action.
Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.
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
int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
Overrides EntityForm::save
File
- src/
Form/ HierarchyChildrenForm.php, line 265
Class
- HierarchyChildrenForm
- Defines a form for re-ordering children.
Namespace
Drupal\entity_hierarchy\FormCode
public function save(array $form, FormStateInterface $form_state) {
$children = $form_state
->getValue('children');
$childEntities = $form_state
->getTemporaryValue(self::CHILD_ENTITIES_STORAGE);
$fieldName = $form_state
->getValue('fieldname');
$batch = [
'title' => new TranslatableMarkup('Reordering children ...'),
'operations' => [],
'finished' => [
static::class,
'finished',
],
];
foreach ($childEntities as $node) {
$childEntity = $childEntities
->offsetGet($node);
if (!$childEntity
->isDefaultRevision()) {
// We don't operate on other than the default revision.
continue;
}
$batch['operations'][] = [
[
static::class,
'reorder',
],
[
$fieldName,
$childEntity,
$children[$node
->getId()]['weight'],
],
];
}
batch_set($batch);
}