fetchBaseTables example


class DefaultWizardDeriver extends DeriverBase {

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $views_data = Views::viewsData();
    $base_tables = array_keys($views_data->fetchBaseTables());
    $this->derivatives = [];
    foreach ($base_tables as $table) {
      $views_info = $views_data->get($table);
      if (empty($views_info['table']['wizard_id'])) {
        $this->derivatives[$table] = [
          'id' => 'standard',
          'base_table' => $table,
          'title' => $views_info['table']['base']['title'],
          'class' => 'Drupal\views\Plugin\views\wizard\Standard',
        ];
      }
    }

  public function submitForm(array &$form, FormStateInterface $form_state) {
    $view = $form_state->get('view');
    foreach ($form_state->getValues() as $key => $value) {
      // Only save values onto the view if they're actual view properties       // (as opposed to 'op' or 'form_build_id').       if (isset($form['details'][$key])) {
        $view->set($key$value);
      }
    }
    $bases = Views::viewsData()->fetchBaseTables();
    $page_title = $view->label();
    if (isset($bases[$view->get('base_table')])) {
      $page_title .= ' (' . $bases[$view->get('base_table')]['title'] . ')';
    }
    $form_state->set('page_title', $page_title);

    $view->cacheSet();
  }

}
$callback(\Closure::fromCallable([$this, 'viewsData']), 'views_test_data');
      });
  }

  /** * Tests the fetchBaseTables() method. */
  public function testFetchBaseTables() {
    $this->setupMockedModuleHandler();
    $data = $this->viewsData->getAll();

    $base_tables = $this->viewsData->fetchBaseTables();

    // Ensure that 'provider' is set for each base table.     foreach (array_keys($base_tables) as $base_table) {
      $this->assertEquals('views_test_data', $data[$base_table]['table']['provider']);
    }

    // Test the number of tables returned and their order.     $this->assertCount(6, $base_tables, 'The correct amount of base tables were returned.');
    $base_tables_keys = array_keys($base_tables);
    for ($i = 1; $i < count($base_tables); ++$i) {
      $prev = $base_tables[$base_tables_keys[$i - 1]];
      
Home | Imprint | This part of the site doesn't use cookies.