Pathauto and dependencies

This commit is contained in:
Rob Davies 2017-05-22 15:12:47 +01:00
parent 4b1a293d57
commit 24ffcb956b
257 changed files with 29510 additions and 0 deletions

View file

@ -0,0 +1,18 @@
ctools_wizard_test.ctools_wizard_test_config_entity.*:
type: config_entity
label: 'Example config entity'
mapping:
id:
type: string
label: 'ID'
label:
type: label
label: 'Label'
uuid:
type: string
one:
type: string
label: 'The first piece of information'
two:
type: string
label: 'The second piece of information'

View file

@ -0,0 +1,12 @@
name: Chaos Wizard Test
type: module
description: 'Provides testing for ctools wizard'
package: Testing
# version: 3.x
# core: 8.x
# Information added by Drupal.org packaging script on 2017-04-28
version: '8.x-3.0'
core: '8.x'
project: 'ctools'
datestamp: 1493401747

View file

@ -0,0 +1,6 @@
entity.ctools_wizard_test_config_entity.add_form:
route_name: 'entity.ctools_wizard_test_config_entity.add_form'
title: 'Add Example config entity'
appears_on:
- entity.ctools_wizard_test_config_entity.collection

View file

@ -0,0 +1,7 @@
# Example config entity menu items definition
entity.ctools_wizard_test_config_entity.collection:
title: 'Example config entity'
route_name: entity.ctools_wizard_test_config_entity.collection
description: 'List Example config entity'
parent: system.admin_structure

View file

@ -0,0 +1,82 @@
ctools.wizard.test:
path: '/ctools/wizard'
defaults:
_wizard: '\Drupal\ctools_wizard_test\Wizard\WizardTest'
_title: 'Wizard Test'
tempstore_id: 'ctools.wizard.test'
machine_name: 'WizardTest'
requirements:
_access: 'TRUE'
ctools.wizard.test.step:
path: '/ctools/wizard/{step}'
defaults:
_wizard: '\Drupal\ctools_wizard_test\Wizard\WizardTest'
_title: 'Wizard Test'
tempstore_id: 'ctools.wizard.test'
machine_name: 'WizardTest'
requirements:
_access: 'TRUE'
# ExampleConfigEntity routing definition
entity.ctools_wizard_test_config_entity.collection:
path: '/admin/structure/ctools_wizard_test_config_entity'
defaults:
_entity_list: 'ctools_wizard_test_config_entity'
_title: 'Example config entity'
requirements:
_permission: 'administer site configuration'
options:
_admin_route: TRUE
entity.ctools_wizard_test_config_entity.add_form:
path: '/admin/structure/ctools_wizard_test_config_entity/add'
defaults:
_entity_wizard: 'ctools_wizard_test_config_entity.add'
_title: 'Add Example config entity'
tempstore_id: 'ctools_wizard_test.config_entity'
requirements:
_permission: 'administer site configuration'
options:
_admin_route: TRUE
entity.ctools_wizard_test_config_entity.add_step_form:
path: '/admin/structure/ctools_wizard_test_config_entity/add/{machine_name}/{step}'
defaults:
_entity_wizard: 'ctools_wizard_test_config_entity.add'
_title: 'Add Example config entity'
tempstore_id: 'ctools_wizard_test.config_entity'
requirements:
_permission: 'administer site configuration'
options:
_admin_route: TRUE
entity.ctools_wizard_test_config_entity.edit_form:
path: '/admin/structure/ctools_wizard_test_config_entity/{machine_name}/{step}'
defaults:
_entity_wizard: 'ctools_wizard_test_config_entity.edit'
_title: 'Edit Example config entity'
tempstore_id: 'ctools_wizard_test.config_entity'
requirements:
_permission: 'administer site configuration'
options:
_admin_route: TRUE
entity.ctools_wizard_test_config_entity.external_form:
path: '/admin/structure/ctools_wizard_test_config_entity/{machine_name}/external'
defaults:
_title: 'Edit Example config entity'
_form: '\Drupal\ctools_wizard_test\Form\ExampleConfigEntityExternalForm'
requirements:
_permission: 'administer site configuration'
options:
_admin_route: TRUE
entity.ctools_wizard_test_config_entity.delete_form:
path: '/admin/structure/ctools_wizard_test_config_entity/{ctools_wizard_test_config_entity}/delete'
defaults:
_entity_form: 'ctools_wizard_test_config_entity.delete'
_title: 'Delete Example config entity'
requirements:
_permission: 'administer site configuration'
options:
_admin_route: TRUE

View file

@ -0,0 +1,83 @@
<?php
namespace Drupal\ctools_wizard_test\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\ctools_wizard_test\ExampleConfigEntityInterface;
/**
* Defines the Example config entity entity.
*
* @ConfigEntityType(
* id = "ctools_wizard_test_config_entity",
* label = @Translation("Example config entity"),
* handlers = {
* "list_builder" = "Drupal\ctools_wizard_test\ExampleConfigEntityListBuilder",
* "form" = {
* "delete" = "Drupal\ctools_wizard_test\Form\ExampleConfigEntityDeleteForm"
* },
* "wizard" = {
* "add" = "Drupal\ctools_wizard_test\Wizard\EntityAddWizardTest",
* "edit" = "Drupal\ctools_wizard_test\Wizard\EntityEditWizardTest"
* }
* },
* config_prefix = "ctools_wizard_test_config_entity",
* admin_permission = "administer site configuration",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* },
* links = {
* "canonical" = "/admin/structure/ctools_wizard_test_config_entity/{ctools_wizard_test_config_entity}",
* "edit-form" = "/admin/structure/ctools_wizard_test_config_entity/{machine_name}/{step}",
* "delete-form" = "/admin/structure/ctools_wizard_test_config_entity/{ctools_wizard_test_config_entity}/delete",
* "collection" = "/admin/structure/ctools_wizard_test_config_entity"
* }
* )
*/
class ExampleConfigEntity extends ConfigEntityBase implements ExampleConfigEntityInterface {
/**
* The Example config entity ID.
*
* @var string
*/
protected $id;
/**
* The Example config entity label.
*
* @var string
*/
protected $label;
/**
* The first piece of information.
*
* @var string
*/
protected $one;
/**
* The second piece of information.
*
* @var string
*/
protected $two;
/**
* @inheritDoc
*/
public function getOne() {
return $this->one;
}
/**
* @inheritDoc
*/
public function getTwo() {
return $this->two;
}
}

View file

@ -0,0 +1,26 @@
<?php
namespace Drupal\ctools_wizard_test;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides an interface for defining Example config entity entities.
*/
interface ExampleConfigEntityInterface extends ConfigEntityInterface {
/**
* Get first piece of information.
*
* @return string
*/
public function getOne();
/**
* Get second piece of information;
*
* @return string
*/
public function getTwo();
}

View file

@ -0,0 +1,49 @@
<?php
namespace Drupal\ctools_wizard_test;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
/**
* Provides a listing of Example config entity entities.
*/
class ExampleConfigEntityListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = $this->t('Example config entity');
$header['id'] = $this->t('Machine name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $this->getLabel($entity);
$row['id'] = $entity->id();
// You probably want a few more properties here...
return $row + parent::buildRow($entity);
}
/**
* @inheritDoc
*/
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
if (!empty($operations['edit'])) {
/** @var \Drupal\Core\Url $edit */
$edit = $operations['edit']['url'];
$edit->setRouteParameters([
'machine_name' => $entity->id(),
'step' => 'general',
]);
}
return $operations;
}
}

View file

@ -0,0 +1,52 @@
<?php
namespace Drupal\ctools_wizard_test\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Builds the form to delete Example config entity entities.
*/
class ExampleConfigEntityDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete %name?', array('%name' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.ctools_wizard_test_config_entity.collection');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message(
$this->t('content @type: deleted @label.',
[
'@type' => $this->entity->bundle(),
'@label' => $this->entity->label()
]
)
);
$form_state->setRedirectUrl($this->getCancelUrl());
}
}

View file

@ -0,0 +1,37 @@
<?php
namespace Drupal\ctools_wizard_test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Simple wizard step form.
*/
class ExampleConfigEntityExistingForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ctools_wizard_test_config_entity_existing_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['existing'] = array(
'#markup' => '<p>This step only shows if the entity is already existing!</p>',
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Do nothing!
}
}

View file

@ -0,0 +1,66 @@
<?php
namespace Drupal\ctools_wizard_test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\user\SharedTempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ExampleConfigEntityExternalForm extends FormBase {
/**
* Tempstore factory.
*
* @var \Drupal\user\SharedTempStoreFactory
*/
protected $tempstore;
/**
* Constructs a new ExampleConfigEntityExternalForm.
*
* @param \Drupal\ctools_wizard_test\Form\SharedTempStoreFactory $tempstore
*/
function __construct(SharedTempStoreFactory $tempstore) {
$this->tempstore = $tempstore;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('user.shared_tempstore'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ctools_wizard_test_example_config_entity_external_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $machine_name = '') {
$cached_values = $this->tempstore->get('ctools_wizard_test.config_entity')->get($machine_name);
/** @var $page \Drupal\ctools_wizard_test\Entity\ExampleConfigEntity */
$config_entity = $cached_values['ctools_wizard_test_config_entity'];
$form['blah'] = [
'#markup' => 'Value from one: ' . $config_entity->getOne(),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Don't do anything.
}
}

View file

@ -0,0 +1,46 @@
<?php
namespace Drupal\ctools_wizard_test\Form;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Class ExampleConfigEntityForm.
*/
class ExampleConfigEntityGeneralForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ctools_wizard_test_config_entity_general_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$cached_values = $form_state->getTemporaryValue('wizard');
/** @var $page \Drupal\ctools_wizard_test\Entity\ExampleConfigEntity */
$config_entity = $cached_values['ctools_wizard_test_config_entity'];
// The label and id will be added by the EntityFormWizardBase.
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$cached_values = $form_state->getTemporaryValue('wizard');
/** @var $page \Drupal\ctools_wizard_test\Entity\ExampleConfigEntity */
$config_entity = $cached_values['ctools_wizard_test_config_entity'];
$config_entity->set('id', $form_state->getValue('id'));
$config_entity->set('label', $form_state->getValue('label'));
}
}

View file

@ -0,0 +1,62 @@
<?php
namespace Drupal\ctools_wizard_test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Simple wizard step form.
*/
class ExampleConfigEntityOneForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ctools_wizard_test_config_entity_one_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$cached_values = $form_state->getTemporaryValue('wizard');
/** @var $page \Drupal\ctools_wizard_test\Entity\ExampleConfigEntity */
$config_entity = $cached_values['ctools_wizard_test_config_entity'];
$form['one'] = [
'#title' => $this->t('One'),
'#type' => 'textfield',
'#default_value' => $config_entity->getOne() ?: '',
];
$form['external'] = [
'#type' => 'link',
'#title' => $this->t('Show on dialog'),
'#url' => new Url('entity.ctools_wizard_test_config_entity.external_form', [
'machine_name' => $config_entity->id(),
]),
'#attributes' => [
'class' => 'use-ajax',
'data-dialog-type' => 'modal',
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$cached_values = $form_state->getTemporaryValue('wizard');
/** @var $page \Drupal\ctools_wizard_test\Entity\ExampleConfigEntity */
$config_entity = $cached_values['ctools_wizard_test_config_entity'];
$config_entity->set('one', $form_state->getValue('one'));
}
}

View file

@ -0,0 +1,47 @@
<?php
namespace Drupal\ctools_wizard_test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Simple wizard step form.
*/
class ExampleConfigEntityTwoForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ctools_wizard_test_config_entity_two_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$cached_values = $form_state->getTemporaryValue('wizard');
/** @var $page \Drupal\ctools_wizard_test\Entity\ExampleConfigEntity */
$config_entity = $cached_values['ctools_wizard_test_config_entity'];
$form['two'] = array(
'#title' => $this->t('Two'),
'#type' => 'textfield',
'#default_value' => $config_entity->getTwo() ?: '',
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$cached_values = $form_state->getTemporaryValue('wizard');
/** @var $page \Drupal\ctools_wizard_test\Entity\ExampleConfigEntity */
$config_entity = $cached_values['ctools_wizard_test_config_entity'];
$config_entity->set('two', $form_state->getValue('two'));
}
}

View file

@ -0,0 +1,71 @@
<?php
namespace Drupal\ctools_wizard_test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Simple wizard step form.
*/
class OneForm extends FormBase {
/**
* Returns a unique string identifying the form.
*
* @return string
* The unique string identifying the form.
*/
public function getFormId() {
return 'ctools_wizard_test_one_form';
}
/**
* Form constructor.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array
* The form structure.
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$cached_values = $form_state->getTemporaryValue('wizard');
$form['one'] = [
'#title' => $this->t('One'),
'#type' => 'textfield',
'#default_value' => !empty($cached_values['one']) ? $cached_values['one'] : '',
];
$form['dynamic'] = [
'#title' => $this->t('Dynamic value'),
'#type' => 'item',
'#markup' => !empty($cached_values['dynamic']) ? $cached_values['dynamic'] : '',
];
return $form;
}
/**
* Form submission handler.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$keys = array(
'one',
);
$cached_values = $form_state->getTemporaryValue('wizard');
foreach ($keys as $key) {
$cached_values[$key] = $form_state->getValue($key);
}
$form_state->setTemporaryValue('wizard', $cached_values);
drupal_set_message($this->t('Dynamic value submitted: @value', ['@value' => $cached_values['dynamic']]));;
}
}

View file

@ -0,0 +1,69 @@
<?php
namespace Drupal\ctools_wizard_test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Simple wizard step form.
*/
class TwoForm extends FormBase {
/**
* Returns a unique string identifying the form.
*
* @return string
* The unique string identifying the form.
*/
public function getFormId() {
return 'ctools_wizard_test_two_form';
}
/**
* Form constructor.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array
* The form structure.
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$cached_values = $form_state->getTemporaryValue('wizard');
$form['two'] = [
'#title' => $this->t('Two'),
'#type' => 'textfield',
'#default_value' => !empty($cached_values['two']) ? $cached_values['two'] : '',
];
$form['dynamic'] = [
'#title' => $this->t('Dynamic value'),
'#type' => 'item',
'#markup' => !empty($cached_values['dynamic']) ? $cached_values['dynamic'] : '',
];
return $form;
}
/**
* Form submission handler.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$keys = array(
'two',
);
$cached_values = $form_state->getTemporaryValue('wizard');
foreach ($keys as $key) {
$cached_values[$key] = $form_state->getValue($key);
}
$form_state->setTemporaryValue('wizard', $cached_values);
}
}

View file

@ -0,0 +1,15 @@
<?php
namespace Drupal\ctools_wizard_test\Wizard;
class EntityAddWizardTest extends EntityEditWizardTest {
/**
* {@inheritdoc}
*/
public function getRouteName() {
return 'entity.ctools_wizard_test_config_entity.add_step_form';
}
}

View file

@ -0,0 +1,71 @@
<?php
namespace Drupal\ctools_wizard_test\Wizard;
use Drupal\ctools\Wizard\EntityFormWizardBase;
class EntityEditWizardTest extends EntityFormWizardBase {
/**
* {@inheritdoc}
*/
public function getWizardLabel() {
return $this->t('Example entity');
}
/**
* {@inheritdoc}
*/
public function getMachineLabel() {
return $this->t('Label');
}
/**
* {@inheritdoc}
*/
public function getEntityType() {
return 'ctools_wizard_test_config_entity';
}
/**
* {@inheritdoc}
*/
public function exists() {
return '\Drupal\ctools_wizard_test\Entity\ExampleConfigEntity::load';
}
/**
* {@inheritdoc}
*/
public function getOperations($cached_values) {
/** @var $page \Drupal\ctools_wizard_test\Entity\ExampleConfigEntity */
$config_entity = $cached_values['ctools_wizard_test_config_entity'];
$steps = [
'general' => [
'form' => 'Drupal\ctools_wizard_test\Form\ExampleConfigEntityGeneralForm',
'title' => $this->t('General'),
],
'one' => [
'form' => 'Drupal\ctools_wizard_test\Form\ExampleConfigEntityOneForm',
'title' => $this->t('Form One'),
],
'two' => [
'form' => 'Drupal\ctools_wizard_test\Form\ExampleConfigEntityTwoForm',
'title' => $this->t('Form Two'),
],
];
// To test that we can get the config entity and add/remove steps
// based on it's values, we'll add a special step only when the entity
// is pre-existing.
if (!empty($config_entity) && !$config_entity->isNew()) {
$steps['existing'] = [
'form' => 'Drupal\ctools_wizard_test\Form\ExampleConfigEntityExistingForm',
'title' => $this->t('Existing entity'),
];
}
return $steps;
}
}

View file

@ -0,0 +1,82 @@
<?php
namespace Drupal\ctools_wizard_test\Wizard;
use Drupal\Core\Form\FormStateInterface;
use Drupal\ctools\Wizard\FormWizardBase;
class WizardTest extends FormWizardBase {
/**
* {@inheritdoc}
*/
public function getWizardLabel() {
return $this->t('Wizard Information');
}
/**
* {@inheritdoc}
*/
public function getMachineLabel() {
return $this->t('Wizard Test Name');
}
/**
* {@inheritdoc}
*/
public function getOperations($cached_values) {
return array(
'one' => [
'form' => 'Drupal\ctools_wizard_test\Form\OneForm',
'title' => $this->t('Form One'),
'values' => ['dynamic' => 'Xylophone'],
'validate' => ['::stepOneValidate'],
'submit' => ['::stepOneSubmit'],
],
'two' => [
'form' => 'Drupal\ctools_wizard_test\Form\TwoForm',
'title' => $this->t('Form Two'),
'values' => ['dynamic' => 'Zebra'],
],
);
}
/**
* Validation callback for the first step.
*/
public function stepOneValidate($form, FormStateInterface $form_state) {
if ($form_state->getValue('one') == 'wrong') {
$form_state->setErrorByName('one', $this->t('Cannot set the value to "wrong".'));
}
}
/**
* Submission callback for the first step.
*/
public function stepOneSubmit($form, FormStateInterface $form_state) {
$cached_values = $form_state->getTemporaryValue('wizard');
if ($form_state->getValue('one') == 'magic') {
$cached_values['one'] = 'Abraham';
}
$form_state->setTemporaryValue('wizard', $cached_values);
}
/**
* {@inheritdoc}
*/
public function getRouteName() {
return 'ctools.wizard.test.step';
}
/**
* {@inheritdoc}
*/
public function finish(array &$form, FormStateInterface $form_state) {
$cached_values = $form_state->getTemporaryValue('wizard');
drupal_set_message($this->t('Value One: @one', ['@one' => $cached_values['one']]));
drupal_set_message($this->t('Value Two: @two', ['@two' => $cached_values['two']]));
parent::finish($form, $form_state);
}
}