addHandler example

// Set the value to use for the filter based on the filter type.                 if ($handler instanceof InOperator) {
                  $options['value'] = [1];
                }
                elseif ($handler instanceof NumericFilter) {
                  $options['value'] = ['value' => 1];
                }
                else {
                  $options['value'] = 1;
                }
              }
              $view->addHandler('default', $type$base_table$field$options);
            }
          }
        }
      }

      // Go through each step individually to see whether some parts are       // failing.       $view->build();
      $view->preExecute();
      $view->execute();
      $view->render();

      
$this->assertIdenticalResultset($view$expected_result$column_map);

    // Test the filter handler. Reuse the same view but replace the argument     // handler with a filter handler.     $view->removeHandler('default', 'argument', 'uid_touch');
    $options = [
      'id' => 'uid_touch',
      'table' => 'node_field_data',
      'field' => 'uid_touch',
      'value' => [$account->id()],
    ];
    $view->addHandler('default', 'filter', 'node_field_data', 'uid_touch', $options);

    $view->preview();
    $this->assertIdenticalResultset($view$expected_result$column_map);
  }

}
      $display->setOverride($section);
    }

    if (!$form_state->isValueEmpty('name') && is_array($form_state->getValue('name'))) {
      // Loop through each of the items that were checked and add them to the view.       foreach (array_keys(array_filter($form_state->getValue('name'))) as $field) {
        [$table$field] = explode('.', $field, 2);

        if ($cut = strpos($field, '$')) {
          $field = substr($field, 0, $cut);
        }
        $id = $this->getExecutable()->addHandler($display_id$type$table$field);

        // check to see if we have group by settings         $key = $type;
        // Footer,header and empty text have a different internal handler type(area).         if (isset($types[$type]['type'])) {
          $key = $types[$type]['type'];
        }
        $item = [
          'table' => $table,
          'field' => $field,
        ];
        
$this->assertTrue($this->assertSession()->optionExists('edit-options-relationship', 'node')->isSelected());
    $this->assertSession()->checkboxChecked('edit-options-value-page');
  }

  /** * Tests the relationship method on the base class. */
  public function testSetRelationship() {
    $view = Views::getView('test_handler_relationships');
    $view->setDisplay();
    // Setup a broken relationship.     $view->addHandler('default', 'relationship', $this->randomMachineName()$this->randomMachineName()[], 'broken_relationship');
    // Setup a valid relationship.     $view->addHandler('default', 'relationship', 'comment_field_data', 'node', ['relationship' => 'cid'], 'valid_relationship');
    $view->initHandlers();
    $field = $view->field['title'];

    $field->options['relationship'] = NULL;
    $field->setRelationship();
    $this->assertNull($field->relationship, 'Make sure that an empty relationship does not create a relationship on the field.');

    $field->options['relationship'] = $this->randomMachineName();
    $field->setRelationship();
    
// Tests item related methods().     $view = $this->controller->create(['base_table' => 'views_test_data']);
    $view->addDisplay('default');
    $view = $view->getExecutable();

    $display_id = 'default';
    $expected_items = [];
    // Tests addHandler with getItem.     // Therefore add one item without any options and one item with some     // options.     $id1 = $view->addHandler($display_id, 'field', 'views_test_data', 'id');
    $item1 = $view->getHandler($display_id, 'field', 'id');
    $expected_items[$id1] = $expected_item = [
      'id' => 'id',
      'table' => 'views_test_data',
      'field' => 'id',
      'plugin_id' => 'numeric',
    ];
    $this->assertEquals($expected_item$item1);

    $options = [
      'alter' => [
        
public function testArgumentDefaultPlugin() {
    $view = Views::getView('test_view');

    // Add a new argument and set the test plugin for the argument_default.     $options = [
      'default_argument_type' => 'argument_default_test',
      'default_argument_options' => [
        'value' => 'John',
      ],
      'default_action' => 'default',
    ];
    $id = $view->addHandler('default', 'argument', 'views_test_data', 'name', $options);
    $view->initHandlers();
    $plugin = $view->argument[$id]->getPlugin('argument_default');
    $this->assertInstanceOf(ArgumentDefaultTestPlugin::class$plugin);

    // Check that the value of the default argument is as expected.     $this->assertEquals('John', $view->argument[$id]->getDefaultArgument(), 'The correct argument default value is returned.');
    // Don't pass in a value for the default argument and make sure the query     // just returns John.     $this->executeView($view);
    $this->assertEquals('John', $view->argument[$id]->getValue(), 'The correct argument value is used.');
    $expected_result = [['name' => 'John']];
    
// Create a new view object on the fly, which we use to generate a query       // object and then get the SQL we need for the subquery.       $temp_view = $this->getTemporaryView();

      // Add the sort from the options to the default display.       // This is broken, in that the sort order field also gets added as a       // select field. See https://www.drupal.org/node/844910.       // We work around this further down.       $sort = $options['subquery_sort'];
      [$sort_table$sort_field] = explode('.', $sort);
      $sort_options = ['order' => $options['subquery_order']];
      $temp_view->addHandler('default', 'sort', $sort_table$sort_field$sort_options);
    }

    // Get the namespace string.     $temp_view->namespace = (!empty($options['subquery_namespace'])) ? '_' . $options['subquery_namespace'] : '_INNER';
    $this->subquery_namespace = (!empty($options['subquery_namespace'])) ? '_' . $options['subquery_namespace'] : 'INNER';

    // The value we add here does nothing, but doing this adds the right tables     // and puts in a WHERE clause with a placeholder we can grab later.     $temp_view->args[] = '**CORRELATED**';

    // Add the base table ID field.

  public function testArgumentValidatorPlugin() {
    $view = Views::getView('test_view');

    // Add a new argument and set the test plugin for the argument_validator.     $options = [
      'specify_validation' => TRUE,
      'validate' => [
        'type' => 'argument_validator_test',
      ],
    ];
    $id = $view->addHandler('default', 'argument', 'views_test_data', 'name', $options);
    $view->initHandlers();

    $test_value = $this->randomMachineName();

    $argument = $view->argument[$id];
    $argument->options['validate_options']['test_value'] = $test_value;
    $this->assertFalse($argument->validateArgument($this->randomMachineName()), 'A random value does not validate.');
    // Reset internal flag.     $argument->argument_validated = NULL;
    $this->assertTrue($argument->validateArgument($test_value), 'The right argument validates.');

    
public function testArgumentDefaultCache() {
    $view = Views::getView('test_view');

    // Add a new argument and set the test plugin for the argument_default.     $options = [
      'default_argument_type' => 'argument_default_test',
      'default_argument_options' => [
        'value' => 'John',
      ],
      'default_action' => 'default',
    ];
    $view->addHandler('default', 'argument', 'views_test_data', 'name', $options);
    $view->initHandlers();

    $output = $view->preview();

    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = \Drupal::service('renderer');

    $renderer->renderPlain($output);
    $this->assertEquals(['config:views.view.test_view', 'example_tag']$output['#cache']['tags']);
  }

}
$display->expects($this->atLeastOnce())
      ->method('setOption')
      ->with($option[
        'test_field' => [
          'id' => 'test_field',
          'table' => 'test_entity',
          'field' => 'test_field',
          'plugin_id' => 'standard',
        ],
      ]);

    $view->addHandler('default', $handler_type, 'test_entity', 'test_field');
  }

  /** * @covers ::addHandler * * @dataProvider addHandlerProvider * * @param string $option * The option to set on the View. * @param $handler_type * The handler type to set. */
Home | Imprint | This part of the site doesn't use cookies.