Unverified Commit 44525221 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2882031 by Lendude, acbramley, RobLoach: Undefined index: identifier in...

Issue #2882031 by Lendude, acbramley, RobLoach: Undefined index: identifier in view's DisplayPluginBase->isIdentifierUnique()

(cherry picked from commit 258c4eac)
parent e6d6b85e
Loading
Loading
Loading
Loading
+1 −1
Changes for core/modules/views/src/Plugin/views/display/DisplayPluginBase.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -2547,7 +2547,7 @@ public function isIdentifierUnique($id, $identifier) {
            }
          }
          else {
            if ($id != $key && $identifier == $handler->options['expose']['identifier']) {
            if ($id != $key && isset($handler->options['expose']['identifier']) && $identifier == $handler->options['expose']['identifier']) {
              return FALSE;
            }
          }
+48 −1
Changes for core/modules/views/tests/src/Kernel/Plugin/DisplayKernelTest.php: 48 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ class DisplayKernelTest extends ViewsKernelTestBase {
   *
   * @var array
   */
  public static $testViews = ['test_display_defaults'];
  public static $testViews = ['test_display_defaults', 'test_view'];

  /**
   * Tests the default display options.
@@ -115,4 +115,51 @@ public function testGetPlugin() {
    $this->assertIdentical($first, $second, 'The same plugin instance was returned.');
  }

  /**
   * Tests the ::isIdentifierUnique method.
   */
  public function testisIdentifierUnique() {
    $view = Views::getView('test_view');
    $view->initDisplay();

    // Add a handler that doesn't have an Identifier when exposed.
    $sorts = [
      'name' => [
        'id' => 'name',
        'field' => 'name',
        'table' => 'views_test_data',
        'plugin_id' => 'standard',
        'order' => 'asc',
        'expose' => ['label' => 'id'],
        'exposed' => TRUE,
      ],
    ];
    // Add a handler that does have an Identifier when exposed.
    $filters = [
      'id' => [
        'field' => 'id',
        'id' => 'id',
        'table' => 'views_test_data',
        'value' => [],
        'plugin_id' => 'numeric',
        'exposed' => TRUE,
        'expose' => [
          'operator_id' => '',
          'label' => 'Id',
          'description' => '',
          'identifier' => 'id',
          'required' => FALSE,
          'remember' => FALSE,
          'multiple' => FALSE,
        ],
      ],
    ];
    $view->display_handler->setOption('sorts', $sorts);
    $view->display_handler->setOption('filters', $filters);
    $view->save();

    $this->assertTrue($view->display_handler->isIdentifierUnique('some_id', 'some_id'));
    $this->assertFalse($view->display_handler->isIdentifierUnique('some_id', 'id'));
  }

}