Hey Drupalistas!

First of all, thank you very much for the effort on this module! It works like a charm.

I noticed, coming from Nodequeue, that there is one (slightly important) function missing.
There is no sort function for "order by in queue or not". You can only do this as a filter.
But if I select the filter is will not show me all the other nodes ... I am forced to put everything in the entityqueue (this will be my workaround).

When using nodequeue I did this:
- sort on "in queue" (desc)
- sort on "position in queue" (asc)
This way I first get my nodes in the queue, ordere by position in the queue and then all the other.

P.S. I looked at the code but could not find a way to add a second sort option on line 57 of entityqueue.views.inc: "$data[$target_base_table]['entityqueue_relationship']['sort'] = array(" so if someone is willing me to help me on that one, I can maybe create it myself.

Comments

yvesvanlaer created an issue. See original summary.

tommychris’s picture

I created the modification, if anybody wants, please create a patch for it:

Create a new file \src\Plugin\views\sort\EntityInQueue.php

<?php
namespace Drupal\entityqueue\Plugin\views\sort;

use Drupal\Core\Session\AccountInterface;
use Drupal\entityqueue\Plugin\views\relationship\EntityQueueRelationship;
use Drupal\views\Plugin\views\sort\SortPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Default implementation of the base sort plugin.
 *
 * @ingroup views_sort_handlers
 *
 * @ViewsSort("entity_in_queue")
 */
class EntityInQueue extends SortPluginBase {

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $currentUser;

  /**
   * Constructor.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param array $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   The current user.
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, AccountInterface $current_user) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);

    $this->currentUser = $current_user;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('current_user')
    );
  }

  /**
   * {@inheritdoc}.
   */
  public function query() {
    $this->ensureMyTable();

    // Try to find an entity queue relationship in this view, and pick the first
    // one available.
    $entity_queue_relationship = NULL;
    foreach ($this->view->relationship as $id => $relationship) {
      if ($relationship instanceof EntityQueueRelationship) {
        $entity_queue_relationship = $relationship;
        $this->options['relationship'] = $id;
        $this->setRelationship();

        break;
      }
    }

    if ($entity_queue_relationship) {
      // Add the field.
      $subqueue_items_table_alias = $entity_queue_relationship->first_alias;
      $this->query->addOrderBy($subqueue_items_table_alias, 'bundle', $this->options['order']);
    }
    else {
      if ($this->currentUser->hasPermission('administer views')) {
        drupal_set_message($this->t('In order to sort by in queue, you need to add the Entityqueue: Queue relationship on View: @view with display: @display', ['@view' => $this->view->storage->label(), '@display' => $this->view->current_display]), 'error');
      }
    }
  }

}

Modify \entityqueue.views.inc, add the following lines after the

$data[$target_base_table]['entityqueue_relationship']['sort'] = array( ...);

block (from line 60 to line 75):

    $data[$target_base_table]['entityqueue_relationship_in_queue']['sort'] = array(
      'id' => 'entity_in_queue',
      'group' => t('Entityqueue'),
      'title' => t('In @target_label queue', array(
        '@target_label' => $entity_type->getLabel(),
      )),
      'label' => t('In @target_label queue', array(
        '@target_label' => $entity_type->getLabel(),
      )),
      'help' => t('Filter to ensure a(n) @target_label IS or IS NOT in the related queue', array(
        '@target_label' => $entity_type->getLabel(),
      )),
      'field' => 'delta',
      'field table' => $subqueue_items_table_name,
      'field_name' => $field_name,
    );
francescbassas’s picture

+1

tommychris’s picture

StatusFileSize
new1013 bytes

Attached a .diff file.

dww’s picture

Status: Active » Needs work

Thanks for turning your contribution into a patch!

However, your patch is missing the new file src\Plugin\views\sort\EntityInQueue.php.

See https://www.drupal.org/node/707484 if you need help learning how to add new files in a patch.

You can set this to "Needs review" once you have a patch that includes everything.

Thanks again,
-Derek

japo32’s picture

Any chance of a d7 version?

sagesolutions’s picture

StatusFileSize
new4.49 KB

See attached patch from the provided code in the comments above

sagesolutions’s picture

Status: Needs work » Needs review
amateescu’s picture

Status: Needs review » Fixed
StatusFileSize
new4.44 KB
new2.17 KB

Made a few corrections and committed to 8.x-1.x. Thanks everyone!

@japo32, let's open a separate issue for porting this patch to D7.

amateescu’s picture

  • amateescu committed f245842 on 8.x-1.x authored by TommyChris
    Issue #2753711 by amateescu, TommyChris, sagesolutions: Sort function if...
japo32’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

andysipple’s picture

StatusFileSize
new32.97 KB

Thank you for the fix! Worked perfectly after updating!