diff --git a/src/Entity/EntityQueue.php b/src/Entity/EntityQueue.php index 7113b25..706bd14 100644 --- a/src/Entity/EntityQueue.php +++ b/src/Entity/EntityQueue.php @@ -143,7 +143,7 @@ class EntityQueue extends ConfigEntityBundleBase implements EntityQueueInterface * {@inheritdoc} */ public function getReverseInAdmin() { - return $this->queue_settings['reverse_in_admin']; + return isset($this->queue_settings['reverse_in_admin']) ? $this->queue_settings['reverse_in_admin'] : FALSE; } /** diff --git a/src/EntityQueueInterface.php b/src/EntityQueueInterface.php index 245918f..d861287 100644 --- a/src/EntityQueueInterface.php +++ b/src/EntityQueueInterface.php @@ -67,6 +67,20 @@ interface EntityQueueInterface extends ConfigEntityInterface { public function getActAsQueue(); /** + * Returns the behavior of editing the queue's items. + * + * Ordinarily, queues are arranged with the front of the queue (where items + * will be removed) on top, and the back (where items will be added) on the + * bottom. + * + * If TRUE, this will display the queue such that items will be added to the + * top and removed from the bottom. + * + * @return bool + */ + public function getReverseInAdmin(); + + /** * Gets the selection settings used by a subqueue's 'items' reference field. * * @return array @@ -87,8 +101,9 @@ interface EntityQueueInterface extends ConfigEntityInterface { * - min_size: The minimum number of items that this queue can hold. * - max_size: The maximum number of items that this queue can hold. * - act_as_queue: The behavior of exceeding the maximum number of queue - * - reverse_in_admin: Show in reverse order in admin view * items. + * - reverse_in_admin: Show the items in reverse order when editing a + * subqueue. */ public function getQueueSettings(); diff --git a/src/Form/EntityQueueForm.php b/src/Form/EntityQueueForm.php index 5781011..2b5114a 100644 --- a/src/Form/EntityQueueForm.php +++ b/src/Form/EntityQueueForm.php @@ -162,9 +162,11 @@ class EntityQueueForm extends BundleEntityFormBase { ]; $form['queue_settings']['reverse_in_admin'] = [ '#type' => 'checkbox', - '#default_value' => $queue->getReverseInAdmin(), '#title' => $this->t('Reverse order in admin view'), + '#default_value' => $queue->getReverseInAdmin(), + '#description' => $this->t('Ordinarily queues are arranged with the front of the queue (where items will be removed) on top and the back (where items will be added) on the bottom. If checked, this will display the queue such that items will be added to the top and removed from the bottom.'), ]; + // We have to duplicate all the code from // \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::fieldSettingsForm() // because field settings forms are not easily embeddable. diff --git a/src/Form/EntitySubqueueForm.php b/src/Form/EntitySubqueueForm.php index 3652255..e6c60c9 100644 --- a/src/Form/EntitySubqueueForm.php +++ b/src/Form/EntitySubqueueForm.php @@ -52,12 +52,14 @@ class EntitySubqueueForm extends ContentEntityForm { * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { - // Reverse in admin form is queue is set to 'Reverse order in admin view' - if($this->entity->getQueue()->getReverseInAdmin()) { + // Reverse the items in the admin form if the queue uses the 'Reverse order + // in admin view' option. + if ($this->entity->getQueue()->getReverseInAdmin()) { $subqueue_items = $this->entity->get('items'); $items_values = $subqueue_items->getValue(); $subqueue_items->setValue(array_reverse($items_values)); } + $form = parent::form($form, $form_state); $form['#title'] = $this->t('Edit subqueue %label', ['%label' => $this->entity->label()]); @@ -161,8 +163,8 @@ class EntitySubqueueForm extends ContentEntityForm { $items_widget->extractFormValues($subqueue_items, $form, $form_state); $items_values = $subqueue_items->getValue(); - // Revert reverse in admin form is queue is set to 'Reverse order in admin view' - if($entity->getQueue()->getReverseInAdmin()) { + // Revert the effect of the 'Reverse order in admin view' option. + if ($entity->getQueue()->getReverseInAdmin()) { $items_values = array_reverse($items_values); } @@ -232,12 +234,14 @@ class EntitySubqueueForm extends ContentEntityForm { */ public function save(array $form, FormStateInterface $form_state) { $subqueue = $this->entity; - // Revert reverse in admin form in queue - if($subqueue->getQueue()->getReverseInAdmin()) { + + // Revert the effect of the 'Reverse order in admin view' option. + if ($subqueue->getQueue()->getReverseInAdmin()) { $subqueue_items = $subqueue->get('items'); $items_values = $subqueue_items->getValue(); $subqueue_items->setValue(array_reverse($items_values)); } + $status = $subqueue->save(); $edit_link = $subqueue->toLink($this->t('Edit'), 'edit-form')->toString();