Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views / src / Plugin / views / query / Sql.php
index 09a754bb433e6521fca77707497028f3ab7512c4..03749a329b3e9235655cb9a3ef141f036a4db41a 100644 (file)
@@ -8,6 +8,7 @@ use Drupal\Core\Database\Database;
 use Drupal\Core\Database\Query\Condition;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Messenger\MessengerInterface;
 use Drupal\views\Plugin\views\display\DisplayPluginBase;
 use Drupal\Core\Database\DatabaseExceptionWrapper;
 use Drupal\views\Plugin\views\join\JoinPluginBase;
@@ -130,6 +131,13 @@ class Sql extends QueryPluginBase {
    */
   protected $dateSql;
 
+  /**
+   * The messenger.
+   *
+   * @var \Drupal\Core\Messenger\MessengerInterface
+   */
+  protected $messenger;
+
   /**
    * Constructs a Sql object.
    *
@@ -143,21 +151,28 @@ class Sql extends QueryPluginBase {
    *   The entity type manager.
    * @param \Drupal\views\Plugin\views\query\DateSqlInterface $date_sql
    *   The database-specific date handler.
+   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
+   *   The messenger.
    */
-  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, DateSqlInterface $date_sql) {
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, DateSqlInterface $date_sql, MessengerInterface $messenger) {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
 
     $this->entityTypeManager = $entity_type_manager;
     $this->dateSql = $date_sql;
+    $this->messenger = $messenger;
   }
 
+  /**
+   * {@inheritdoc}
+   */
   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
     return new static(
       $configuration,
       $plugin_id,
       $plugin_definition,
       $container->get('entity_type.manager'),
-      $container->get('views.date_sql')
+      $container->get('views.date_sql'),
+      $container->get('messenger')
     );
   }
 
@@ -173,7 +188,7 @@ class Sql extends QueryPluginBase {
       'link' => NULL,
       'table' => $base_table,
       'alias' => $base_table,
-      'base' => $base_table
+      'base' => $base_table,
     ];
 
     // init the table queue with our primary table.
@@ -1030,7 +1045,7 @@ class Sql extends QueryPluginBase {
 
     $this->orderby[] = [
       'field' => $as,
-      'direction' => strtoupper($order)
+      'direction' => strtoupper($order),
     ];
   }
 
@@ -1498,7 +1513,7 @@ class Sql extends QueryPluginBase {
 
         if (!empty($this->limit) || !empty($this->offset)) {
           // We can't have an offset without a limit, so provide a very large limit instead.
-          $limit  = intval(!empty($this->limit) ? $this->limit : 999999);
+          $limit = intval(!empty($this->limit) ? $this->limit : 999999);
           $offset = intval(!empty($this->offset) ? $this->offset : 0);
           $query->range($offset, $limit);
         }
@@ -1522,7 +1537,7 @@ class Sql extends QueryPluginBase {
       catch (DatabaseExceptionWrapper $e) {
         $view->result = [];
         if (!empty($view->live_preview)) {
-          drupal_set_message($e->getMessage(), 'error');
+          $this->messenger->addError($e->getMessage());
         }
         else {
           throw new DatabaseExceptionWrapper("Exception in {$view->storage->label()}[{$view->storage->id()}]: {$e->getMessage()}");
@@ -1778,7 +1793,7 @@ class Sql extends QueryPluginBase {
           'filter' => 'groupby_numeric',
           'sort' => 'groupby_numeric',
         ],
-      ]
+      ],
     ];
   }