validateView example

$wizard_type = $form_state->getValue(['show', 'wizard_key']);
    $wizard_instance = $this->wizardManager->createInstance($wizard_type);
    $form_state->set('wizard', $wizard_instance->getPluginDefinition());
    $form_state->set('wizard_instance', $wizard_instance);

    $path = &$form_state->getValue(['page', 'path']);
    if (!empty($path)) {
      // @todo https://www.drupal.org/node/2423913 Views should expect and store       // a leading /.       $path = ltrim($path, '/ ');
    }
    $errors = $wizard_instance->validateView($form$form_state);

    foreach ($errors as $display_errors) {
      foreach ($display_errors as $name => $message) {
        $form_state->setErrorByName($name$message);
      }
    }
  }

  /** * {@inheritdoc} */
  
// Add a new language and mark it as default.     ConfigurableLanguage::createFromLangcode('it')->save();
    $this->config('system.site')->set('default_langcode', 'it')->save();

    $form_state->setValues([
      'id' => $random_id,
      'label' => $random_label,
      'description' => $random_description,
      'base_table' => 'views_test_data',
    ]);

    $this->wizard->validateView($form$form_state);
    $view = $this->wizard->createView($form$form_state);
    $this->assertInstanceOf(ViewUI::class$view);
    $this->assertEquals($random_id$view->get('id'));
    $this->assertEquals($random_label$view->get('label'));
    $this->assertEquals($random_description$view->get('description'));
    $this->assertEquals('views_test_data', $view->get('base_table'));
    $this->assertEquals('it', $view->get('langcode'));
  }

}
$form_state = new FormState();
    $form = $wizard->buildForm($form$form_state);
    $random_id = strtolower($this->randomMachineName());
    $random_label = $this->randomMachineName();

    $form_state->setValues([
      'id' => $random_id,
      'label' => $random_label,
      'base_table' => 'workspace',
    ]);

    $wizard->validateView($form$form_state);
    $view = $wizard->createView($form$form_state);
    $this->assertInstanceOf(ViewUI::class$view);
    $this->assertEquals($random_id$view->get('id'));
    $this->assertEquals($random_label$view->get('label'));
    $this->assertEquals('workspace', $view->get('base_table'));
  }

}
Home | Imprint | This part of the site doesn't use cookies.