public function NodeOrderListBuilder::submitForm in Node Order 8
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
NodeOrderListBuilder.php, line 272
Class
- NodeOrderListBuilder
- Defines a class to build a listing of node entities.
Namespace
Drupal\nodeorderCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$term_id = $form_state
->getValue('term_id');
$nodes = $form_state
->getValue($this->entitiesKey);
$nids = array_keys($nodes);
$tags = [];
$entities = $this->storage
->loadMultiple($nids);
foreach ($entities as $nid => $node) {
// Only take form elements that are blocks.
if (isset($this->entities[$nid]) && $this->nodesWeight[$nid] !== $nodes[$nid]['weight']) {
$this->database
->update('taxonomy_index')
->fields([
'weight' => $nodes[$nid]['weight'],
])
->condition('tid', $term_id)
->condition('nid', $nid)
->execute();
$tags = array_merge($tags, $node
->getCacheTags());
}
}
$this
->messenger()
->addStatus($this
->t('The node orders have been updated.'));
if (!empty($tags)) {
$this->cacheTagsInvalidator
->invalidateTags($tags);
}
$this->cacheDefault
->deleteAll();
}