Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
|
@ -17,20 +17,20 @@ class EntityDisplayModeController extends ControllerBase {
|
|||
* A list of entity types to add a view mode for.
|
||||
*/
|
||||
public function viewModeTypeSelection() {
|
||||
$entity_types = array();
|
||||
$entity_types = [];
|
||||
foreach ($this->entityManager()->getDefinitions() as $entity_type_id => $entity_type) {
|
||||
if ($entity_type->get('field_ui_base_route') && $entity_type->hasViewBuilderClass()) {
|
||||
$entity_types[$entity_type_id] = array(
|
||||
$entity_types[$entity_type_id] = [
|
||||
'title' => $entity_type->getLabel(),
|
||||
'url' => Url::fromRoute('entity.entity_view_mode.add_form', array('entity_type_id' => $entity_type_id)),
|
||||
'localized_options' => array(),
|
||||
);
|
||||
'url' => Url::fromRoute('entity.entity_view_mode.add_form', ['entity_type_id' => $entity_type_id]),
|
||||
'localized_options' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
return array(
|
||||
return [
|
||||
'#theme' => 'admin_block_content',
|
||||
'#content' => $entity_types,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -40,20 +40,20 @@ class EntityDisplayModeController extends ControllerBase {
|
|||
* A list of entity types to add a form mode for.
|
||||
*/
|
||||
public function formModeTypeSelection() {
|
||||
$entity_types = array();
|
||||
$entity_types = [];
|
||||
foreach ($this->entityManager()->getDefinitions() as $entity_type_id => $entity_type) {
|
||||
if ($entity_type->get('field_ui_base_route') && $entity_type->hasFormClasses()) {
|
||||
$entity_types[$entity_type_id] = array(
|
||||
$entity_types[$entity_type_id] = [
|
||||
'title' => $entity_type->getLabel(),
|
||||
'url' => Url::fromRoute('entity.entity_form_mode.add_form', array('entity_type_id' => $entity_type_id)),
|
||||
'localized_options' => array(),
|
||||
);
|
||||
'url' => Url::fromRoute('entity.entity_form_mode.add_form', ['entity_type_id' => $entity_type_id]),
|
||||
'localized_options' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
return array(
|
||||
return [
|
||||
'#theme' => 'admin_block_content',
|
||||
'#content' => $entity_types,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class FieldUiTable extends Table {
|
|||
* @see \Drupal\Core\Render\Element\Table::preRenderTable()
|
||||
*/
|
||||
public static function tablePreRender($elements) {
|
||||
$js_settings = array();
|
||||
$js_settings = [];
|
||||
|
||||
// For each region, build the tree structure from the weight and parenting
|
||||
// data contained in the flat form structure, to determine row order and
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class EntityDisplayModeListBuilder extends ConfigEntityListBuilder {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function load() {
|
||||
$entities = array();
|
||||
$entities = [];
|
||||
foreach (parent::load() as $entity) {
|
||||
$entities[$entity->getTargetType()][] = $entity;
|
||||
}
|
||||
|
|
@ -82,7 +82,7 @@ class EntityDisplayModeListBuilder extends ConfigEntityListBuilder {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function render() {
|
||||
$build = array();
|
||||
$build = [];
|
||||
foreach ($this->load() as $entity_type => $entities) {
|
||||
if (!isset($this->entityTypes[$entity_type])) {
|
||||
continue;
|
||||
|
|
@ -93,12 +93,12 @@ class EntityDisplayModeListBuilder extends ConfigEntityListBuilder {
|
|||
continue;
|
||||
}
|
||||
|
||||
$table = array(
|
||||
$table = [
|
||||
'#prefix' => '<h2>' . $this->entityTypes[$entity_type]->getLabel() . '</h2>',
|
||||
'#type' => 'table',
|
||||
'#header' => $this->buildHeader(),
|
||||
'#rows' => array(),
|
||||
);
|
||||
'#rows' => [],
|
||||
];
|
||||
foreach ($entities as $entity) {
|
||||
if ($row = $this->buildRow($entity)) {
|
||||
$table['#rows'][$entity->id()] = $row;
|
||||
|
|
@ -110,15 +110,15 @@ class EntityDisplayModeListBuilder extends ConfigEntityListBuilder {
|
|||
$table['#weight'] = -10;
|
||||
}
|
||||
|
||||
$short_type = str_replace(array('entity_', '_mode'), '', $this->entityTypeId);
|
||||
$table['#rows']['_add_new'][] = array(
|
||||
'data' => array(
|
||||
$short_type = str_replace(['entity_', '_mode'], '', $this->entityTypeId);
|
||||
$table['#rows']['_add_new'][] = [
|
||||
'data' => [
|
||||
'#type' => 'link',
|
||||
'#url' => Url::fromRoute($short_type == 'view' ? 'entity.entity_view_mode.add_form' : 'entity.entity_form_mode.add_form', ['entity_type_id' => $entity_type]),
|
||||
'#title' => $this->t('Add new %label @entity-type', array('%label' => $this->entityTypes[$entity_type]->getLabel(), '@entity-type' => $this->entityType->getLowercaseLabel())),
|
||||
),
|
||||
'#title' => $this->t('Add new %label @entity-type', ['%label' => $this->entityTypes[$entity_type]->getLabel(), '@entity-type' => $this->entityType->getLowercaseLabel()]),
|
||||
],
|
||||
'colspan' => count($table['#header']),
|
||||
);
|
||||
];
|
||||
$build[$entity_type] = $table;
|
||||
}
|
||||
return $build;
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ class FieldConfigListBuilder extends ConfigEntityListBuilder {
|
|||
|
||||
// Sort the entities using the entity class's sort() method.
|
||||
// See \Drupal\Core\Config\Entity\ConfigEntityBase::sort().
|
||||
uasort($entities, array($this->entityType->getClass(), 'sort'));
|
||||
uasort($entities, [$this->entityType->getClass(), 'sort']);
|
||||
return $entities;
|
||||
}
|
||||
|
||||
|
|
@ -101,14 +101,14 @@ class FieldConfigListBuilder extends ConfigEntityListBuilder {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header = array(
|
||||
$header = [
|
||||
'label' => $this->t('Label'),
|
||||
'field_name' => array(
|
||||
'field_name' => [
|
||||
'data' => $this->t('Machine name'),
|
||||
'class' => array(RESPONSIVE_PRIORITY_MEDIUM),
|
||||
),
|
||||
'class' => [RESPONSIVE_PRIORITY_MEDIUM],
|
||||
],
|
||||
'field_type' => $this->t('Field type'),
|
||||
);
|
||||
];
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
|
|
@ -118,31 +118,31 @@ class FieldConfigListBuilder extends ConfigEntityListBuilder {
|
|||
public function buildRow(EntityInterface $field_config) {
|
||||
/** @var \Drupal\field\FieldConfigInterface $field_config */
|
||||
$field_storage = $field_config->getFieldStorageDefinition();
|
||||
$route_parameters = array(
|
||||
$route_parameters = [
|
||||
'field_config' => $field_config->id(),
|
||||
) + FieldUI::getRouteBundleParameter($this->entityManager->getDefinition($this->targetEntityTypeId), $this->targetBundle);
|
||||
] + FieldUI::getRouteBundleParameter($this->entityManager->getDefinition($this->targetEntityTypeId), $this->targetBundle);
|
||||
|
||||
$row = array(
|
||||
$row = [
|
||||
'id' => Html::getClass($field_config->getName()),
|
||||
'data' => array(
|
||||
'data' => [
|
||||
'label' => $field_config->getLabel(),
|
||||
'field_name' => $field_config->getName(),
|
||||
'field_type' => array(
|
||||
'data' => array(
|
||||
'field_type' => [
|
||||
'data' => [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->fieldTypeManager->getDefinitions()[$field_storage->getType()]['label'],
|
||||
'#url' => Url::fromRoute("entity.field_config.{$this->targetEntityTypeId}_storage_edit_form", $route_parameters),
|
||||
'#options' => array('attributes' => array('title' => $this->t('Edit field settings.'))),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
'#options' => ['attributes' => ['title' => $this->t('Edit field settings.')]],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// Add the operations.
|
||||
$row['data'] = $row['data'] + parent::buildRow($field_config);
|
||||
|
||||
if ($field_storage->isLocked()) {
|
||||
$row['data']['operations'] = array('data' => array('#markup' => $this->t('Locked')));
|
||||
$row['data']['operations'] = ['data' => ['#markup' => $this->t('Locked')]];
|
||||
$row['class'][] = 'menu-disabled';
|
||||
}
|
||||
|
||||
|
|
@ -157,26 +157,26 @@ class FieldConfigListBuilder extends ConfigEntityListBuilder {
|
|||
$operations = parent::getDefaultOperations($entity);
|
||||
|
||||
if ($entity->access('update') && $entity->hasLinkTemplate("{$entity->getTargetEntityTypeId()}-field-edit-form")) {
|
||||
$operations['edit'] = array(
|
||||
$operations['edit'] = [
|
||||
'title' => $this->t('Edit'),
|
||||
'weight' => 10,
|
||||
'url' => $entity->urlInfo("{$entity->getTargetEntityTypeId()}-field-edit-form"),
|
||||
);
|
||||
];
|
||||
}
|
||||
if ($entity->access('delete') && $entity->hasLinkTemplate("{$entity->getTargetEntityTypeId()}-field-delete-form")) {
|
||||
$operations['delete'] = array(
|
||||
$operations['delete'] = [
|
||||
'title' => $this->t('Delete'),
|
||||
'weight' => 100,
|
||||
'url' => $entity->urlInfo("{$entity->getTargetEntityTypeId()}-field-delete-form"),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$operations['storage-settings'] = array(
|
||||
$operations['storage-settings'] = [
|
||||
'title' => $this->t('Storage settings'),
|
||||
'weight' => 20,
|
||||
'attributes' => array('title' => $this->t('Edit storage settings.')),
|
||||
'attributes' => ['title' => $this->t('Edit storage settings.')],
|
||||
'url' => $entity->urlInfo("{$entity->getTargetEntityTypeId()}-storage-edit-form"),
|
||||
);
|
||||
];
|
||||
$operations['edit']['attributes']['title'] = $this->t('Edit field settings.');
|
||||
$operations['delete']['attributes']['title'] = $this->t('Delete field.');
|
||||
|
||||
|
|
|
|||
|
|
@ -82,10 +82,10 @@ class FieldStorageConfigListBuilder extends ConfigEntityListBuilder {
|
|||
*/
|
||||
public function buildHeader() {
|
||||
$header['id'] = $this->t('Field name');
|
||||
$header['type'] = array(
|
||||
$header['type'] = [
|
||||
'data' => $this->t('Field type'),
|
||||
'class' => array(RESPONSIVE_PRIORITY_MEDIUM),
|
||||
);
|
||||
'class' => [RESPONSIVE_PRIORITY_MEDIUM],
|
||||
];
|
||||
$header['usage'] = $this->t('Used in');
|
||||
return $header;
|
||||
}
|
||||
|
|
@ -95,17 +95,17 @@ class FieldStorageConfigListBuilder extends ConfigEntityListBuilder {
|
|||
*/
|
||||
public function buildRow(EntityInterface $field_storage) {
|
||||
if ($field_storage->isLocked()) {
|
||||
$row['class'] = array('menu-disabled');
|
||||
$row['data']['id'] = $this->t('@field_name (Locked)', array('@field_name' => $field_storage->getName()));
|
||||
$row['class'] = ['menu-disabled'];
|
||||
$row['data']['id'] = $this->t('@field_name (Locked)', ['@field_name' => $field_storage->getName()]);
|
||||
}
|
||||
else {
|
||||
$row['data']['id'] = $field_storage->getName();
|
||||
}
|
||||
|
||||
$field_type = $this->fieldTypes[$field_storage->getType()];
|
||||
$row['data']['type'] = $this->t('@type (module: @module)', array('@type' => $field_type['label'], '@module' => $field_type['provider']));
|
||||
$row['data']['type'] = $this->t('@type (module: @module)', ['@type' => $field_type['label'], '@module' => $field_type['provider']]);
|
||||
|
||||
$usage = array();
|
||||
$usage = [];
|
||||
foreach ($field_storage->getBundles() as $bundle) {
|
||||
$entity_type_id = $field_storage->getTargetEntityTypeId();
|
||||
if ($route_info = FieldUI::getOverviewRouteInfo($entity_type_id, $bundle)) {
|
||||
|
|
|
|||
|
|
@ -47,9 +47,9 @@ class FieldUI {
|
|||
$next_destination = array_shift($destinations);
|
||||
if (is_array($next_destination)) {
|
||||
$next_destination['options']['query']['destinations'] = $destinations;
|
||||
$next_destination += array(
|
||||
'route_parameters' => array(),
|
||||
);
|
||||
$next_destination += [
|
||||
'route_parameters' => [],
|
||||
];
|
||||
$next_destination = Url::fromRoute($next_destination['route_name'], $next_destination['route_parameters'], $next_destination['options']);
|
||||
}
|
||||
else {
|
||||
|
|
@ -77,7 +77,7 @@ class FieldUI {
|
|||
*/
|
||||
public static function getRouteBundleParameter(EntityTypeInterface $entity_type, $bundle) {
|
||||
$bundle_parameter_key = $entity_type->getBundleEntityType() ?: 'bundle';
|
||||
return array($bundle_parameter_key => $bundle);
|
||||
return [$bundle_parameter_key => $bundle];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,17 +90,17 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
* @endcode
|
||||
*/
|
||||
public function getRegions() {
|
||||
return array(
|
||||
'content' => array(
|
||||
return [
|
||||
'content' => [
|
||||
'title' => $this->t('Content'),
|
||||
'invisible' => TRUE,
|
||||
'message' => $this->t('No field is displayed.')
|
||||
),
|
||||
'hidden' => array(
|
||||
'title' => $this->t('Disabled', array(), array('context' => 'Plural')),
|
||||
],
|
||||
'hidden' => [
|
||||
'title' => $this->t('Disabled', [], ['context' => 'Plural']),
|
||||
'message' => $this->t('No field is hidden.')
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -110,7 +110,7 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
* An array containing the region options.
|
||||
*/
|
||||
public function getRegionOptions() {
|
||||
$options = array();
|
||||
$options = [];
|
||||
foreach ($this->getRegions() as $region => $data) {
|
||||
$options[$region] = $data['title'];
|
||||
}
|
||||
|
|
@ -139,41 +139,48 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
$field_definitions = $this->getFieldDefinitions();
|
||||
$extra_fields = $this->getExtraFields();
|
||||
|
||||
$form += array(
|
||||
$form += [
|
||||
'#entity_type' => $this->entity->getTargetEntityTypeId(),
|
||||
'#bundle' => $this->entity->getTargetBundle(),
|
||||
'#fields' => array_keys($field_definitions),
|
||||
'#extra' => array_keys($extra_fields),
|
||||
);
|
||||
];
|
||||
|
||||
if (empty($field_definitions) && empty($extra_fields) && $route_info = FieldUI::getOverviewRouteInfo($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle())) {
|
||||
drupal_set_message($this->t('There are no fields yet added. You can add new fields on the <a href=":link">Manage fields</a> page.', array(':link' => $route_info->toString())), 'warning');
|
||||
drupal_set_message($this->t('There are no fields yet added. You can add new fields on the <a href=":link">Manage fields</a> page.', [':link' => $route_info->toString()]), 'warning');
|
||||
return $form;
|
||||
}
|
||||
|
||||
$table = array(
|
||||
$table = [
|
||||
'#type' => 'field_ui_table',
|
||||
'#header' => $this->getTableHeader(),
|
||||
'#regions' => $this->getRegions(),
|
||||
'#attributes' => array(
|
||||
'class' => array('field-ui-overview'),
|
||||
'#attributes' => [
|
||||
'class' => ['field-ui-overview'],
|
||||
'id' => 'field-display-overview',
|
||||
),
|
||||
'#tabledrag' => array(
|
||||
array(
|
||||
],
|
||||
'#tabledrag' => [
|
||||
[
|
||||
'action' => 'order',
|
||||
'relationship' => 'sibling',
|
||||
'group' => 'field-weight',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'action' => 'match',
|
||||
'relationship' => 'parent',
|
||||
'group' => 'field-parent',
|
||||
'subgroup' => 'field-parent',
|
||||
'source' => 'field-name',
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
[
|
||||
'action' => 'match',
|
||||
'relationship' => 'parent',
|
||||
'group' => 'field-region',
|
||||
'subgroup' => 'field-region',
|
||||
'source' => 'field-name',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// Field rows.
|
||||
foreach ($field_definitions as $field_name => $field_definition) {
|
||||
|
|
@ -194,21 +201,21 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
// Unset default option.
|
||||
unset($display_mode_options['default']);
|
||||
if ($display_mode_options) {
|
||||
$form['modes'] = array(
|
||||
$form['modes'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Custom display settings'),
|
||||
);
|
||||
];
|
||||
// Prepare default values for the 'Custom display settings' checkboxes.
|
||||
$default = array();
|
||||
$default = [];
|
||||
if ($enabled_displays = array_filter($this->getDisplayStatuses())) {
|
||||
$default = array_keys(array_intersect_key($display_mode_options, $enabled_displays));
|
||||
}
|
||||
$form['modes']['display_modes_custom'] = array(
|
||||
$form['modes']['display_modes_custom'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => $this->t('Use custom display settings for the following @display_context modes', ['@display_context' => $this->displayContext]),
|
||||
'#options' => $display_mode_options,
|
||||
'#default_value' => $default,
|
||||
);
|
||||
];
|
||||
// Provide link to manage display modes.
|
||||
$form['modes']['display_modes_link'] = $this->getDisplayModesLink();
|
||||
}
|
||||
|
|
@ -220,29 +227,29 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
// the selects, but triggered by the client-side script through a hidden
|
||||
// #ajax 'Refresh' button. A hidden 'refresh_rows' input tracks the name of
|
||||
// affected rows.
|
||||
$form['refresh_rows'] = array('#type' => 'hidden');
|
||||
$form['refresh'] = array(
|
||||
$form['refresh_rows'] = ['#type' => 'hidden'];
|
||||
$form['refresh'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Refresh'),
|
||||
'#op' => 'refresh_table',
|
||||
'#submit' => array('::multistepSubmit'),
|
||||
'#ajax' => array(
|
||||
'#submit' => ['::multistepSubmit'],
|
||||
'#ajax' => [
|
||||
'callback' => '::multistepAjax',
|
||||
'wrapper' => 'field-display-overview-wrapper',
|
||||
'effect' => 'fade',
|
||||
// The button stays hidden, so we hide the Ajax spinner too. Ad-hoc
|
||||
// spinners will be added manually by the client-side script.
|
||||
'progress' => 'none',
|
||||
),
|
||||
'#attributes' => array('class' => array('visually-hidden'))
|
||||
);
|
||||
],
|
||||
'#attributes' => ['class' => ['visually-hidden']]
|
||||
];
|
||||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#button_type' => 'primary',
|
||||
'#value' => $this->t('Save'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['#attached']['library'][] = 'field_ui/drupal.field_ui';
|
||||
|
||||
|
|
@ -274,74 +281,82 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
}
|
||||
|
||||
$regions = array_keys($this->getRegions());
|
||||
$field_row = array(
|
||||
'#attributes' => array('class' => array('draggable', 'tabledrag-leaf')),
|
||||
$field_row = [
|
||||
'#attributes' => ['class' => ['draggable', 'tabledrag-leaf']],
|
||||
'#row_type' => 'field',
|
||||
'#region_callback' => array($this, 'getRowRegion'),
|
||||
'#js_settings' => array(
|
||||
'#region_callback' => [$this, 'getRowRegion'],
|
||||
'#js_settings' => [
|
||||
'rowHandler' => 'field',
|
||||
'defaultPlugin' => $this->getDefaultPlugin($field_definition->getType()),
|
||||
),
|
||||
'human_name' => array(
|
||||
],
|
||||
'human_name' => [
|
||||
'#plain_text' => $label,
|
||||
),
|
||||
'weight' => array(
|
||||
],
|
||||
'weight' => [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Weight for @title', array('@title' => $label)),
|
||||
'#title' => $this->t('Weight for @title', ['@title' => $label]),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $display_options ? $display_options['weight'] : '0',
|
||||
'#size' => 3,
|
||||
'#attributes' => array('class' => array('field-weight')),
|
||||
),
|
||||
'parent_wrapper' => array(
|
||||
'parent' => array(
|
||||
'#attributes' => ['class' => ['field-weight']],
|
||||
],
|
||||
'parent_wrapper' => [
|
||||
'parent' => [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Label display for @title', array('@title' => $label)),
|
||||
'#title' => $this->t('Label display for @title', ['@title' => $label]),
|
||||
'#title_display' => 'invisible',
|
||||
'#options' => array_combine($regions, $regions),
|
||||
'#empty_value' => '',
|
||||
'#attributes' => array('class' => array('js-field-parent', 'field-parent')),
|
||||
'#parents' => array('fields', $field_name, 'parent'),
|
||||
),
|
||||
'hidden_name' => array(
|
||||
'#attributes' => ['class' => ['js-field-parent', 'field-parent']],
|
||||
'#parents' => ['fields', $field_name, 'parent'],
|
||||
],
|
||||
'hidden_name' => [
|
||||
'#type' => 'hidden',
|
||||
'#default_value' => $field_name,
|
||||
'#attributes' => array('class' => array('field-name')),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$field_row['plugin'] = array(
|
||||
'type' => array(
|
||||
'#attributes' => ['class' => ['field-name']],
|
||||
],
|
||||
],
|
||||
'region' => [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Plugin for @title', array('@title' => $label)),
|
||||
'#title' => $this->t('Region for @title', ['@title' => $label]),
|
||||
'#title_display' => 'invisible',
|
||||
'#options' => $this->getPluginOptions($field_definition),
|
||||
'#options' => $this->getRegionOptions(),
|
||||
'#default_value' => $display_options ? $display_options['region'] : 'hidden',
|
||||
'#attributes' => ['class' => ['field-region']],
|
||||
],
|
||||
];
|
||||
|
||||
$field_row['plugin'] = [
|
||||
'type' => [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Plugin for @title', ['@title' => $label]),
|
||||
'#title_display' => 'invisible',
|
||||
'#options' => $this->getApplicablePluginOptions($field_definition),
|
||||
'#default_value' => $display_options ? $display_options['type'] : 'hidden',
|
||||
'#parents' => array('fields', $field_name, 'type'),
|
||||
'#attributes' => array('class' => array('field-plugin-type')),
|
||||
),
|
||||
'settings_edit_form' => array(),
|
||||
);
|
||||
'#parents' => ['fields', $field_name, 'type'],
|
||||
'#attributes' => ['class' => ['field-plugin-type']],
|
||||
],
|
||||
'settings_edit_form' => [],
|
||||
];
|
||||
|
||||
// Get the corresponding plugin object.
|
||||
$plugin = $this->entity->getRenderer($field_name);
|
||||
|
||||
// Base button element for the various plugin settings actions.
|
||||
$base_button = array(
|
||||
'#submit' => array('::multistepSubmit'),
|
||||
'#ajax' => array(
|
||||
$base_button = [
|
||||
'#submit' => ['::multistepSubmit'],
|
||||
'#ajax' => [
|
||||
'callback' => '::multistepAjax',
|
||||
'wrapper' => 'field-display-overview-wrapper',
|
||||
'effect' => 'fade',
|
||||
),
|
||||
],
|
||||
'#field_name' => $field_name,
|
||||
);
|
||||
];
|
||||
|
||||
if ($form_state->get('plugin_settings_edit') == $field_name) {
|
||||
// We are currently editing this field's plugin settings. Display the
|
||||
// settings form and submit buttons.
|
||||
$field_row['plugin']['settings_edit_form'] = array();
|
||||
$field_row['plugin']['settings_edit_form'] = [];
|
||||
|
||||
if ($plugin) {
|
||||
// Generate the settings form and allow other modules to alter it.
|
||||
|
|
@ -349,43 +364,43 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
$third_party_settings_form = $this->thirdPartySettingsForm($plugin, $field_definition, $form, $form_state);
|
||||
|
||||
if ($settings_form || $third_party_settings_form) {
|
||||
$field_row['plugin']['#cell_attributes'] = array('colspan' => 3);
|
||||
$field_row['plugin']['settings_edit_form'] = array(
|
||||
$field_row['plugin']['#cell_attributes'] = ['colspan' => 3];
|
||||
$field_row['plugin']['settings_edit_form'] = [
|
||||
'#type' => 'container',
|
||||
'#attributes' => array('class' => array('field-plugin-settings-edit-form')),
|
||||
'#parents' => array('fields', $field_name, 'settings_edit_form'),
|
||||
'label' => array(
|
||||
'#attributes' => ['class' => ['field-plugin-settings-edit-form']],
|
||||
'#parents' => ['fields', $field_name, 'settings_edit_form'],
|
||||
'label' => [
|
||||
'#markup' => $this->t('Plugin settings'),
|
||||
),
|
||||
],
|
||||
'settings' => $settings_form,
|
||||
'third_party_settings' => $third_party_settings_form,
|
||||
'actions' => array(
|
||||
'actions' => [
|
||||
'#type' => 'actions',
|
||||
'save_settings' => $base_button + array(
|
||||
'save_settings' => $base_button + [
|
||||
'#type' => 'submit',
|
||||
'#button_type' => 'primary',
|
||||
'#name' => $field_name . '_plugin_settings_update',
|
||||
'#value' => $this->t('Update'),
|
||||
'#op' => 'update',
|
||||
),
|
||||
'cancel_settings' => $base_button + array(
|
||||
],
|
||||
'cancel_settings' => $base_button + [
|
||||
'#type' => 'submit',
|
||||
'#name' => $field_name . '_plugin_settings_cancel',
|
||||
'#value' => $this->t('Cancel'),
|
||||
'#op' => 'cancel',
|
||||
// Do not check errors for the 'Cancel' button, but make sure we
|
||||
// get the value of the 'plugin type' select.
|
||||
'#limit_validation_errors' => array(array('fields', $field_name, 'type')),
|
||||
),
|
||||
),
|
||||
);
|
||||
'#limit_validation_errors' => [['fields', $field_name, 'type']],
|
||||
],
|
||||
],
|
||||
];
|
||||
$field_row['#attributes']['class'][] = 'field-plugin-settings-editing';
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$field_row['settings_summary'] = array();
|
||||
$field_row['settings_edit'] = array();
|
||||
$field_row['settings_summary'] = [];
|
||||
$field_row['settings_edit'] = [];
|
||||
|
||||
if ($plugin) {
|
||||
// Display a summary of the current plugin settings, and (if the
|
||||
|
|
@ -396,30 +411,30 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
$this->alterSettingsSummary($summary, $plugin, $field_definition);
|
||||
|
||||
if (!empty($summary)) {
|
||||
$field_row['settings_summary'] = array(
|
||||
$field_row['settings_summary'] = [
|
||||
'#type' => 'inline_template',
|
||||
'#template' => '<div class="field-plugin-summary">{{ summary|safe_join("<br />") }}</div>',
|
||||
'#context' => array('summary' => $summary),
|
||||
'#cell_attributes' => array('class' => array('field-plugin-summary-cell')),
|
||||
);
|
||||
'#context' => ['summary' => $summary],
|
||||
'#cell_attributes' => ['class' => ['field-plugin-summary-cell']],
|
||||
];
|
||||
}
|
||||
|
||||
// Check selected plugin settings to display edit link or not.
|
||||
$settings_form = $plugin->settingsForm($form, $form_state);
|
||||
$third_party_settings_form = $this->thirdPartySettingsForm($plugin, $field_definition, $form, $form_state);
|
||||
if (!empty($settings_form) || !empty($third_party_settings_form)) {
|
||||
$field_row['settings_edit'] = $base_button + array(
|
||||
$field_row['settings_edit'] = $base_button + [
|
||||
'#type' => 'image_button',
|
||||
'#name' => $field_name . '_settings_edit',
|
||||
'#src' => 'core/misc/icons/787878/cog.svg',
|
||||
'#attributes' => array('class' => array('field-plugin-settings-edit'), 'alt' => $this->t('Edit')),
|
||||
'#attributes' => ['class' => ['field-plugin-settings-edit'], 'alt' => $this->t('Edit')],
|
||||
'#op' => 'edit',
|
||||
// Do not check errors for the 'Edit' button, but make sure we get
|
||||
// the value of the 'plugin type' select.
|
||||
'#limit_validation_errors' => array(array('fields', $field_name, 'type')),
|
||||
'#limit_validation_errors' => [['fields', $field_name, 'type']],
|
||||
'#prefix' => '<div class="field-plugin-settings-edit-wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -442,52 +457,57 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
$display_options = $this->entity->getComponent($field_id);
|
||||
|
||||
$regions = array_keys($this->getRegions());
|
||||
$extra_field_row = array(
|
||||
'#attributes' => array('class' => array('draggable', 'tabledrag-leaf')),
|
||||
$extra_field_row = [
|
||||
'#attributes' => ['class' => ['draggable', 'tabledrag-leaf']],
|
||||
'#row_type' => 'extra_field',
|
||||
'#region_callback' => array($this, 'getRowRegion'),
|
||||
'#js_settings' => array('rowHandler' => 'field'),
|
||||
'human_name' => array(
|
||||
'#region_callback' => [$this, 'getRowRegion'],
|
||||
'#js_settings' => ['rowHandler' => 'field'],
|
||||
'human_name' => [
|
||||
'#markup' => $extra_field['label'],
|
||||
),
|
||||
'weight' => array(
|
||||
],
|
||||
'weight' => [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Weight for @title', array('@title' => $extra_field['label'])),
|
||||
'#title' => $this->t('Weight for @title', ['@title' => $extra_field['label']]),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $display_options ? $display_options['weight'] : 0,
|
||||
'#size' => 3,
|
||||
'#attributes' => array('class' => array('field-weight')),
|
||||
),
|
||||
'parent_wrapper' => array(
|
||||
'parent' => array(
|
||||
'#attributes' => ['class' => ['field-weight']],
|
||||
],
|
||||
'parent_wrapper' => [
|
||||
'parent' => [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Parents for @title', array('@title' => $extra_field['label'])),
|
||||
'#title' => $this->t('Parents for @title', ['@title' => $extra_field['label']]),
|
||||
'#title_display' => 'invisible',
|
||||
'#options' => array_combine($regions, $regions),
|
||||
'#empty_value' => '',
|
||||
'#attributes' => array('class' => array('js-field-parent', 'field-parent')),
|
||||
'#parents' => array('fields', $field_id, 'parent'),
|
||||
),
|
||||
'hidden_name' => array(
|
||||
'#attributes' => ['class' => ['js-field-parent', 'field-parent']],
|
||||
'#parents' => ['fields', $field_id, 'parent'],
|
||||
],
|
||||
'hidden_name' => [
|
||||
'#type' => 'hidden',
|
||||
'#default_value' => $field_id,
|
||||
'#attributes' => array('class' => array('field-name')),
|
||||
),
|
||||
),
|
||||
'plugin' => array(
|
||||
'type' => array(
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Visibility for @title', array('@title' => $extra_field['label'])),
|
||||
'#title_display' => 'invisible',
|
||||
'#options' => $this->getExtraFieldVisibilityOptions(),
|
||||
'#default_value' => $display_options ? 'visible' : 'hidden',
|
||||
'#parents' => array('fields', $field_id, 'type'),
|
||||
'#attributes' => array('class' => array('field-plugin-type')),
|
||||
),
|
||||
),
|
||||
'settings_summary' => array(),
|
||||
'settings_edit' => array(),
|
||||
);
|
||||
'#attributes' => ['class' => ['field-name']],
|
||||
],
|
||||
],
|
||||
'region' => [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Region for @title', ['@title' => $extra_field['label']]),
|
||||
'#title_display' => 'invisible',
|
||||
'#options' => $this->getRegionOptions(),
|
||||
'#default_value' => $display_options ? $display_options['region'] : 'hidden',
|
||||
'#attributes' => ['class' => ['field-region']],
|
||||
],
|
||||
'plugin' => [
|
||||
'type' => [
|
||||
'#type' => 'hidden',
|
||||
'#value' => $display_options ? 'visible' : 'hidden',
|
||||
'#parents' => ['fields', $field_id, 'type'],
|
||||
'#attributes' => ['class' => ['field-plugin-type']],
|
||||
],
|
||||
],
|
||||
'settings_summary' => [],
|
||||
'settings_edit' => [],
|
||||
];
|
||||
|
||||
return $extra_field_row;
|
||||
}
|
||||
|
|
@ -511,7 +531,7 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
$display_modes = $this->getDisplayModes();
|
||||
$current_statuses = $this->getDisplayStatuses();
|
||||
|
||||
$statuses = array();
|
||||
$statuses = [];
|
||||
foreach ($form_values['display_modes_custom'] as $mode => $value) {
|
||||
if (!empty($value) && empty($current_statuses[$mode])) {
|
||||
// If no display exists for the newly enabled view mode, initialize
|
||||
|
|
@ -550,7 +570,7 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
foreach ($form['#fields'] as $field_name) {
|
||||
$values = $form_values['fields'][$field_name];
|
||||
|
||||
if ($values['type'] == 'hidden') {
|
||||
if ($values['region'] == 'hidden') {
|
||||
$entity->removeComponent($field_name);
|
||||
}
|
||||
else {
|
||||
|
|
@ -567,6 +587,7 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
|
||||
$options['type'] = $values['type'];
|
||||
$options['weight'] = $values['weight'];
|
||||
$options['region'] = $values['region'];
|
||||
// Only formatters have configurable label visibility.
|
||||
if (isset($values['label'])) {
|
||||
$options['label'] = $values['label'];
|
||||
|
|
@ -577,13 +598,14 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
|
||||
// Collect data for 'extra' fields.
|
||||
foreach ($form['#extra'] as $name) {
|
||||
if ($form_values['fields'][$name]['type'] == 'hidden') {
|
||||
if ($form_values['fields'][$name]['region'] == 'hidden') {
|
||||
$entity->removeComponent($name);
|
||||
}
|
||||
else {
|
||||
$entity->setComponent($name, array(
|
||||
$entity->setComponent($name, [
|
||||
'weight' => $form_values['fields'][$name]['weight'],
|
||||
));
|
||||
'region' => $form_values['fields'][$name]['region'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -640,19 +662,19 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
// Pick the elements that need to receive the ajax-new-content effect.
|
||||
switch ($op) {
|
||||
case 'edit':
|
||||
$updated_rows = array($trigger['#field_name']);
|
||||
$updated_columns = array('plugin');
|
||||
$updated_rows = [$trigger['#field_name']];
|
||||
$updated_columns = ['plugin'];
|
||||
break;
|
||||
|
||||
case 'update':
|
||||
case 'cancel':
|
||||
$updated_rows = array($trigger['#field_name']);
|
||||
$updated_columns = array('plugin', 'settings_summary', 'settings_edit');
|
||||
$updated_rows = [$trigger['#field_name']];
|
||||
$updated_columns = ['plugin', 'settings_summary', 'settings_edit'];
|
||||
break;
|
||||
|
||||
case 'refresh_table':
|
||||
$updated_rows = array_values(explode(' ', $form_state->getValue('refresh_rows')));
|
||||
$updated_columns = array('settings_summary', 'settings_edit');
|
||||
$updated_columns = ['settings_summary', 'settings_edit'];
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -712,7 +734,7 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
protected function getExtraFields() {
|
||||
$context = $this->displayContext == 'view' ? 'display' : $this->displayContext;
|
||||
$extra_fields = $this->entityManager->getExtraFields($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle());
|
||||
return isset($extra_fields[$context]) ? $extra_fields[$context] : array();
|
||||
return isset($extra_fields[$context]) ? $extra_fields[$context] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -741,7 +763,7 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
*/
|
||||
protected function getApplicablePluginOptions(FieldDefinitionInterface $field_definition) {
|
||||
$options = $this->pluginManager->getOptions($field_definition->getType());
|
||||
$applicable_options = array();
|
||||
$applicable_options = [];
|
||||
foreach ($options as $option => $label) {
|
||||
$plugin_class = DefaultFactory::getPluginClass($option, $this->pluginManager->getDefinition($option));
|
||||
if ($plugin_class::isApplicable($field_definition)) {
|
||||
|
|
@ -751,20 +773,6 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
return $applicable_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of widget or formatter options for a field.
|
||||
*
|
||||
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
|
||||
* The field definition.
|
||||
*
|
||||
* @return array
|
||||
* An array of widget or formatter options.
|
||||
*/
|
||||
protected function getPluginOptions(FieldDefinitionInterface $field_definition) {
|
||||
$applicable_options = $this->getApplicablePluginOptions($field_definition);
|
||||
return $applicable_options + array('hidden' => '- ' . $this->t('Hidden') . ' -');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of the default widget or formatter plugin for a field type.
|
||||
*
|
||||
|
|
@ -813,23 +821,10 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
switch ($row['#row_type']) {
|
||||
case 'field':
|
||||
case 'extra_field':
|
||||
return ($row['plugin']['type']['#value'] == 'hidden' ? 'hidden' : 'content');
|
||||
return $row['region']['#value'] ?: 'hidden';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of visibility options for extra fields.
|
||||
*
|
||||
* @return array
|
||||
* An array of visibility options.
|
||||
*/
|
||||
protected function getExtraFieldVisibilityOptions() {
|
||||
return array(
|
||||
'visible' => $this->t('Visible'),
|
||||
'hidden' => '- ' . $this->t('Hidden') . ' -',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns entity (form) displays for the current entity display type.
|
||||
*
|
||||
|
|
@ -837,7 +832,7 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
* An array holding entity displays or entity form displays.
|
||||
*/
|
||||
protected function getDisplays() {
|
||||
$load_ids = array();
|
||||
$load_ids = [];
|
||||
$display_entity_type = $this->entity->getEntityTypeId();
|
||||
$entity_type = $this->entityManager->getDefinition($display_entity_type);
|
||||
$config_prefix = $entity_type->getConfigPrefix();
|
||||
|
|
@ -859,7 +854,7 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
* An array of form or view mode statuses.
|
||||
*/
|
||||
protected function getDisplayStatuses() {
|
||||
$display_statuses = array();
|
||||
$display_statuses = [];
|
||||
$displays = $this->getDisplays();
|
||||
foreach ($displays as $display) {
|
||||
$display_statuses[$display->get('mode')] = $display->status();
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class EntityDisplayModeAddForm extends EntityDisplayModeFormBase {
|
|||
// Change replace_pattern to avoid undesired dots.
|
||||
$form['id']['#machine_name']['replace_pattern'] = '[^a-z0-9_]+';
|
||||
$definition = $this->entityManager->getDefinition($this->targetEntityTypeId);
|
||||
$form['#title'] = $this->t('Add new %label @entity-type', array('%label' => $definition->getLabel(), '@entity-type' => $this->entityType->getLowercaseLabel()));
|
||||
$form['#title'] = $this->t('Add new %label @entity-type', ['%label' => $definition->getLabel(), '@entity-type' => $this->entityType->getLowercaseLabel()]);
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class EntityDisplayModeDeleteForm extends EntityDeleteForm {
|
|||
*/
|
||||
public function getDescription() {
|
||||
$entity_type = $this->entity->getEntityType();
|
||||
return $this->t('Deleting a @entity-type will cause any output still requesting to use that @entity-type to use the default display settings.', array('@entity-type' => $entity_type->getLowercaseLabel()));
|
||||
return $this->t('Deleting a @entity-type will cause any output still requesting to use that @entity-type to use the default display settings.', ['@entity-type' => $entity_type->getLowercaseLabel()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,23 +3,13 @@
|
|||
namespace Drupal\field_ui\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides the generic base class for entity display mode forms.
|
||||
*/
|
||||
abstract class EntityDisplayModeFormBase extends EntityForm {
|
||||
|
||||
/**
|
||||
* The entity query factory.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $queryFactory;
|
||||
|
||||
/**
|
||||
* The entity type definition.
|
||||
*
|
||||
|
|
@ -27,66 +17,36 @@ abstract class EntityDisplayModeFormBase extends EntityForm {
|
|||
*/
|
||||
protected $entityType;
|
||||
|
||||
/**
|
||||
* The entity manager.
|
||||
*
|
||||
* @var \Drupal\Component\Plugin\PluginManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* Constructs a new EntityDisplayModeFormBase.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
|
||||
* The entity query factory.
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
*/
|
||||
public function __construct(QueryFactory $query_factory, EntityManagerInterface $entity_manager) {
|
||||
$this->queryFactory = $query_factory;
|
||||
$this->entityManager = $entity_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.query'),
|
||||
$container->get('entity.manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function init(FormStateInterface $form_state) {
|
||||
parent::init($form_state);
|
||||
$this->entityType = $this->entityManager->getDefinition($this->entity->getEntityTypeId());
|
||||
$this->entityType = $this->entityTypeManager->getDefinition($this->entity->getEntityTypeId());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$form['label'] = array(
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Name'),
|
||||
'#maxlength' => 100,
|
||||
'#default_value' => $this->entity->label(),
|
||||
);
|
||||
];
|
||||
|
||||
$form['id'] = array(
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#description' => $this->t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'),
|
||||
'#disabled' => !$this->entity->isNew(),
|
||||
'#default_value' => $this->entity->id(),
|
||||
'#field_prefix' => $this->entity->isNew() ? $this->entity->getTargetType() . '.' : '',
|
||||
'#machine_name' => array(
|
||||
'exists' => array($this, 'exists'),
|
||||
'#machine_name' => [
|
||||
'exists' => [$this, 'exists'],
|
||||
'replace_pattern' => '[^a-z0-9_.]+',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
@ -107,8 +67,9 @@ abstract class EntityDisplayModeFormBase extends EntityForm {
|
|||
if ($entity_id == 'default') {
|
||||
return TRUE;
|
||||
}
|
||||
return (bool) $this->queryFactory
|
||||
->get($this->entity->getEntityTypeId())
|
||||
return (bool) $this->entityTypeManager
|
||||
->getStorage($this->entity->getEntityTypeId())
|
||||
->getQuery()
|
||||
->condition('id', $element['#field_prefix'] . $entity_id)
|
||||
->execute();
|
||||
}
|
||||
|
|
@ -117,7 +78,7 @@ abstract class EntityDisplayModeFormBase extends EntityForm {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
drupal_set_message($this->t('Saved the %label @entity-type.', array('%label' => $this->entity->label(), '@entity-type' => $this->entityType->getLowercaseLabel())));
|
||||
drupal_set_message($this->t('Saved the %label @entity-type.', ['%label' => $this->entity->label(), '@entity-type' => $this->entityType->getLowercaseLabel()]));
|
||||
$this->entity->save();
|
||||
\Drupal::entityManager()->clearCachedFieldDefinitions();
|
||||
$form_state->setRedirectUrl($this->entity->urlInfo('collection'));
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class EntityFormDisplayEditForm extends EntityDisplayFormBase {
|
|||
$field_name = $field_definition->getName();
|
||||
|
||||
// Update the (invisible) title of the 'plugin' column.
|
||||
$field_row['plugin']['#title'] = $this->t('Formatter for @title', array('@title' => $field_definition->getLabel()));
|
||||
$field_row['plugin']['#title'] = $this->t('Formatter for @title', ['@title' => $field_definition->getLabel()]);
|
||||
if (!empty($field_row['plugin']['settings_edit_form']) && ($plugin = $this->entity->getRenderer($field_name))) {
|
||||
$plugin_type_info = $plugin->getPluginDefinition();
|
||||
$field_row['plugin']['settings_edit_form']['label']['#markup'] = $this->t('Widget settings:') . ' <span class="plugin-name">' . $plugin_type_info['label'] . '</span>';
|
||||
|
|
@ -90,12 +90,13 @@ class EntityFormDisplayEditForm extends EntityDisplayFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTableHeader() {
|
||||
return array(
|
||||
return [
|
||||
$this->t('Field'),
|
||||
$this->t('Weight'),
|
||||
$this->t('Parent'),
|
||||
array('data' => $this->t('Widget'), 'colspan' => 3),
|
||||
);
|
||||
$this->t('Region'),
|
||||
['data' => $this->t('Widget'), 'colspan' => 3],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -112,17 +113,17 @@ class EntityFormDisplayEditForm extends EntityDisplayFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) {
|
||||
$settings_form = array();
|
||||
$settings_form = [];
|
||||
// Invoke hook_field_widget_third_party_settings_form(), keying resulting
|
||||
// subforms by module name.
|
||||
foreach ($this->moduleHandler->getImplementations('field_widget_third_party_settings_form') as $module) {
|
||||
$settings_form[$module] = $this->moduleHandler->invoke($module, 'field_widget_third_party_settings_form', array(
|
||||
$settings_form[$module] = $this->moduleHandler->invoke($module, 'field_widget_third_party_settings_form', [
|
||||
$plugin,
|
||||
$field_definition,
|
||||
$this->entity->getMode(),
|
||||
$form,
|
||||
$form_state,
|
||||
));
|
||||
]);
|
||||
}
|
||||
return $settings_form;
|
||||
}
|
||||
|
|
@ -131,11 +132,11 @@ class EntityFormDisplayEditForm extends EntityDisplayFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function alterSettingsSummary(array &$summary, PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition) {
|
||||
$context = array(
|
||||
$context = [
|
||||
'widget' => $plugin,
|
||||
'field_definition' => $field_definition,
|
||||
'form_mode' => $this->entity->getMode(),
|
||||
);
|
||||
];
|
||||
$this->moduleHandler->alter('field_widget_settings_summary', $summary, $context);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,21 +39,21 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase {
|
|||
$display_options = $this->entity->getComponent($field_name);
|
||||
|
||||
// Insert the label column.
|
||||
$label = array(
|
||||
'label' => array(
|
||||
$label = [
|
||||
'label' => [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Label display for @title', array('@title' => $field_definition->getLabel())),
|
||||
'#title' => $this->t('Label display for @title', ['@title' => $field_definition->getLabel()]),
|
||||
'#title_display' => 'invisible',
|
||||
'#options' => $this->getFieldLabelOptions(),
|
||||
'#default_value' => $display_options ? $display_options['label'] : 'above',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$label_position = array_search('plugin', array_keys($field_row));
|
||||
$field_row = array_slice($field_row, 0, $label_position, TRUE) + $label + array_slice($field_row, $label_position, count($field_row) - 1, TRUE);
|
||||
|
||||
// Update the (invisible) title of the 'plugin' column.
|
||||
$field_row['plugin']['#title'] = $this->t('Formatter for @title', array('@title' => $field_definition->getLabel()));
|
||||
$field_row['plugin']['#title'] = $this->t('Formatter for @title', ['@title' => $field_definition->getLabel()]);
|
||||
if (!empty($field_row['plugin']['settings_edit_form']) && ($plugin = $this->entity->getRenderer($field_name))) {
|
||||
$plugin_type_info = $plugin->getPluginDefinition();
|
||||
$field_row['plugin']['settings_edit_form']['label']['#markup'] = $this->t('Format settings:') . ' <span class="plugin-name">' . $plugin_type_info['label'] . '</span>';
|
||||
|
|
@ -69,11 +69,11 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase {
|
|||
$extra_field_row = parent::buildExtraFieldRow($field_id, $extra_field);
|
||||
|
||||
// Insert an empty placeholder for the label column.
|
||||
$label = array(
|
||||
'empty_cell' => array(
|
||||
$label = [
|
||||
'empty_cell' => [
|
||||
'#markup' => ' '
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
$label_position = array_search('plugin', array_keys($extra_field_row));
|
||||
$extra_field_row = array_slice($extra_field_row, 0, $label_position, TRUE) + $label + array_slice($extra_field_row, $label_position, count($extra_field_row) - 1, TRUE);
|
||||
|
||||
|
|
@ -123,13 +123,14 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTableHeader() {
|
||||
return array(
|
||||
return [
|
||||
$this->t('Field'),
|
||||
$this->t('Weight'),
|
||||
$this->t('Parent'),
|
||||
$this->t('Region'),
|
||||
$this->t('Label'),
|
||||
array('data' => $this->t('Format'), 'colspan' => 3),
|
||||
);
|
||||
['data' => $this->t('Format'), 'colspan' => 3],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -149,29 +150,29 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase {
|
|||
* An array of visibility options.
|
||||
*/
|
||||
protected function getFieldLabelOptions() {
|
||||
return array(
|
||||
return [
|
||||
'above' => $this->t('Above'),
|
||||
'inline' => $this->t('Inline'),
|
||||
'hidden' => '- ' . $this->t('Hidden') . ' -',
|
||||
'visually_hidden' => '- ' . $this->t('Visually Hidden') . ' -',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) {
|
||||
$settings_form = array();
|
||||
$settings_form = [];
|
||||
// Invoke hook_field_formatter_third_party_settings_form(), keying resulting
|
||||
// subforms by module name.
|
||||
foreach ($this->moduleHandler->getImplementations('field_formatter_third_party_settings_form') as $module) {
|
||||
$settings_form[$module] = $this->moduleHandler->invoke($module, 'field_formatter_third_party_settings_form', array(
|
||||
$settings_form[$module] = $this->moduleHandler->invoke($module, 'field_formatter_third_party_settings_form', [
|
||||
$plugin,
|
||||
$field_definition,
|
||||
$this->entity->getMode(),
|
||||
$form,
|
||||
$form_state,
|
||||
));
|
||||
]);
|
||||
}
|
||||
return $settings_form;
|
||||
}
|
||||
|
|
@ -180,11 +181,11 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function alterSettingsSummary(array &$summary, PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition) {
|
||||
$context = array(
|
||||
$context = [
|
||||
'formatter' => $plugin,
|
||||
'field_definition' => $field_definition,
|
||||
'view_mode' => $this->entity->getMode(),
|
||||
);
|
||||
];
|
||||
$this->moduleHandler->alter('field_formatter_settings_summary', $summary, $context);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,10 +96,10 @@ class FieldConfigDeleteForm extends EntityDeleteForm {
|
|||
|
||||
if ($field_storage && !$field_storage->isLocked()) {
|
||||
$this->entity->delete();
|
||||
drupal_set_message($this->t('The field %field has been deleted from the %type content type.', array('%field' => $this->entity->label(), '%type' => $bundle_label)));
|
||||
drupal_set_message($this->t('The field %field has been deleted from the %type content type.', ['%field' => $this->entity->label(), '%type' => $bundle_label]));
|
||||
}
|
||||
else {
|
||||
drupal_set_message($this->t('There was a problem removing the %field from the %type content type.', array('%field' => $this->entity->label(), '%type' => $bundle_label)), 'error');
|
||||
drupal_set_message($this->t('There was a problem removing the %field from the %type content type.', ['%field' => $this->entity->label(), '%type' => $bundle_label]), 'error');
|
||||
}
|
||||
|
||||
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||
|
|
|
|||
|
|
@ -33,75 +33,75 @@ class FieldConfigEditForm extends EntityForm {
|
|||
$field_storage = $this->entity->getFieldStorageDefinition();
|
||||
$bundles = $this->entityManager->getBundleInfo($this->entity->getTargetEntityTypeId());
|
||||
|
||||
$form_title = $this->t('%field settings for %bundle', array(
|
||||
$form_title = $this->t('%field settings for %bundle', [
|
||||
'%field' => $this->entity->getLabel(),
|
||||
'%bundle' => $bundles[$this->entity->getTargetBundle()]['label'],
|
||||
));
|
||||
]);
|
||||
$form['#title'] = $form_title;
|
||||
|
||||
if ($field_storage->isLocked()) {
|
||||
$form['locked'] = array(
|
||||
'#markup' => $this->t('The field %field is locked and cannot be edited.', array('%field' => $this->entity->getLabel())),
|
||||
);
|
||||
$form['locked'] = [
|
||||
'#markup' => $this->t('The field %field is locked and cannot be edited.', ['%field' => $this->entity->getLabel()]),
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
// Build the configurable field values.
|
||||
$form['label'] = array(
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Label'),
|
||||
'#default_value' => $this->entity->getLabel() ?: $field_storage->getName(),
|
||||
'#required' => TRUE,
|
||||
'#weight' => -20,
|
||||
);
|
||||
];
|
||||
|
||||
$form['description'] = array(
|
||||
$form['description'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => $this->t('Help text'),
|
||||
'#default_value' => $this->entity->getDescription(),
|
||||
'#rows' => 5,
|
||||
'#description' => $this->t('Instructions to present to the user below this field on the editing form.<br />Allowed HTML tags: @tags', array('@tags' => FieldFilteredMarkup::displayAllowedTags())) . '<br />' . $this->t('This field supports tokens.'),
|
||||
'#description' => $this->t('Instructions to present to the user below this field on the editing form.<br />Allowed HTML tags: @tags', ['@tags' => FieldFilteredMarkup::displayAllowedTags()]) . '<br />' . $this->t('This field supports tokens.'),
|
||||
'#weight' => -10,
|
||||
);
|
||||
];
|
||||
|
||||
$form['required'] = array(
|
||||
$form['required'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Required field'),
|
||||
'#default_value' => $this->entity->isRequired(),
|
||||
'#weight' => -5,
|
||||
);
|
||||
];
|
||||
|
||||
// Create an arbitrary entity object (used by the 'default value' widget).
|
||||
$ids = (object) array(
|
||||
$ids = (object) [
|
||||
'entity_type' => $this->entity->getTargetEntityTypeId(),
|
||||
'bundle' => $this->entity->getTargetBundle(),
|
||||
'entity_id' => NULL
|
||||
);
|
||||
];
|
||||
$form['#entity'] = _field_create_entity_from_ids($ids);
|
||||
$items = $form['#entity']->get($this->entity->getName());
|
||||
$item = $items->first() ?: $items->appendItem();
|
||||
|
||||
// Add field settings for the field type and a container for third party
|
||||
// settings that modules can add to via hook_form_FORM_ID_alter().
|
||||
$form['settings'] = array(
|
||||
$form['settings'] = [
|
||||
'#tree' => TRUE,
|
||||
'#weight' => 10,
|
||||
);
|
||||
];
|
||||
$form['settings'] += $item->fieldSettingsForm($form, $form_state);
|
||||
$form['third_party_settings'] = array(
|
||||
$form['third_party_settings'] = [
|
||||
'#tree' => TRUE,
|
||||
'#weight' => 11,
|
||||
);
|
||||
];
|
||||
|
||||
// Add handling for default value.
|
||||
if ($element = $items->defaultValuesForm($form, $form_state)) {
|
||||
$element = array_merge($element, array(
|
||||
$element = array_merge($element, [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Default value'),
|
||||
'#open' => TRUE,
|
||||
'#tree' => TRUE,
|
||||
'#description' => $this->t('The default value for this field, used when creating new content.'),
|
||||
));
|
||||
]);
|
||||
|
||||
$form['default_value'] = $element;
|
||||
}
|
||||
|
|
@ -128,15 +128,15 @@ class FieldConfigEditForm extends EntityForm {
|
|||
$query['destination'] = $this->getRequest()->query->get('destination');
|
||||
$url->setOption('query', $query);
|
||||
}
|
||||
$actions['delete'] = array(
|
||||
$actions['delete'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $this->t('Delete'),
|
||||
'#url' => $url,
|
||||
'#access' => $this->entity->access('delete'),
|
||||
'#attributes' => array(
|
||||
'class' => array('button', 'button--danger'),
|
||||
),
|
||||
);
|
||||
'#attributes' => [
|
||||
'class' => ['button', 'button--danger'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $actions;
|
||||
|
|
@ -161,7 +161,7 @@ class FieldConfigEditForm extends EntityForm {
|
|||
parent::submitForm($form, $form_state);
|
||||
|
||||
// Handle the default value.
|
||||
$default_value = array();
|
||||
$default_value = [];
|
||||
if (isset($form['default_value'])) {
|
||||
$items = $form['#entity']->get($this->entity->getName());
|
||||
$default_value = $items->defaultValuesFormSubmit($form['default_value'], $form, $form_state);
|
||||
|
|
@ -175,7 +175,7 @@ class FieldConfigEditForm extends EntityForm {
|
|||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$this->entity->save();
|
||||
|
||||
drupal_set_message($this->t('Saved %label configuration.', array('%label' => $this->entity->getLabel())));
|
||||
drupal_set_message($this->t('Saved %label configuration.', ['%label' => $this->entity->getLabel()]));
|
||||
|
||||
$request = $this->getRequest();
|
||||
if (($destinations = $request->query->get('destinations')) && $next_destination = FieldUI::getNextDestination($destinations)) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace Drupal\field_ui\Form;
|
||||
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
|
|
@ -46,13 +45,6 @@ class FieldStorageAddForm extends FormBase {
|
|||
*/
|
||||
protected $fieldTypePluginManager;
|
||||
|
||||
/**
|
||||
* The query factory to create entity queries.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
public $queryFactory;
|
||||
|
||||
/**
|
||||
* The configuration factory.
|
||||
*
|
||||
|
|
@ -67,15 +59,12 @@ class FieldStorageAddForm extends FormBase {
|
|||
* The entity manager.
|
||||
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_plugin_manager
|
||||
* The field type plugin manager.
|
||||
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
|
||||
* The entity query factory.
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
||||
* The configuration factory.
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_plugin_manager, QueryFactory $query_factory, ConfigFactoryInterface $config_factory) {
|
||||
public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_plugin_manager, ConfigFactoryInterface $config_factory) {
|
||||
$this->entityManager = $entity_manager;
|
||||
$this->fieldTypePluginManager = $field_type_plugin_manager;
|
||||
$this->queryFactory = $query_factory;
|
||||
$this->configFactory = $config_factory;
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +82,6 @@ class FieldStorageAddForm extends FormBase {
|
|||
return new static(
|
||||
$container->get('entity.manager'),
|
||||
$container->get('plugin.manager.field.field_type'),
|
||||
$container->get('entity.query'),
|
||||
$container->get('config.factory')
|
||||
);
|
||||
}
|
||||
|
|
@ -113,65 +101,65 @@ class FieldStorageAddForm extends FormBase {
|
|||
$this->bundle = $form_state->get('bundle');
|
||||
|
||||
// Gather valid field types.
|
||||
$field_type_options = array();
|
||||
$field_type_options = [];
|
||||
foreach ($this->fieldTypePluginManager->getGroupedDefinitions($this->fieldTypePluginManager->getUiDefinitions()) as $category => $field_types) {
|
||||
foreach ($field_types as $name => $field_type) {
|
||||
$field_type_options[$category][$name] = $field_type['label'];
|
||||
}
|
||||
}
|
||||
|
||||
$form['add'] = array(
|
||||
$form['add'] = [
|
||||
'#type' => 'container',
|
||||
'#attributes' => array('class' => array('form--inline', 'clearfix')),
|
||||
);
|
||||
'#attributes' => ['class' => ['form--inline', 'clearfix']],
|
||||
];
|
||||
|
||||
$form['add']['new_storage_type'] = array(
|
||||
$form['add']['new_storage_type'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Add a new field'),
|
||||
'#options' => $field_type_options,
|
||||
'#empty_option' => $this->t('- Select a field type -'),
|
||||
);
|
||||
];
|
||||
|
||||
// Re-use existing field.
|
||||
if ($existing_field_storage_options = $this->getExistingFieldStorageOptions()) {
|
||||
$form['add']['separator'] = array(
|
||||
$form['add']['separator'] = [
|
||||
'#type' => 'item',
|
||||
'#markup' => $this->t('or'),
|
||||
);
|
||||
$form['add']['existing_storage_name'] = array(
|
||||
];
|
||||
$form['add']['existing_storage_name'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Re-use an existing field'),
|
||||
'#options' => $existing_field_storage_options,
|
||||
'#empty_option' => $this->t('- Select an existing field -'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['#attached']['drupalSettings']['existingFieldLabels'] = $this->getExistingFieldLabels(array_keys($existing_field_storage_options));
|
||||
}
|
||||
else {
|
||||
// Provide a placeholder form element to simplify the validation code.
|
||||
$form['add']['existing_storage_name'] = array(
|
||||
$form['add']['existing_storage_name'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => FALSE,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Field label and field_name.
|
||||
$form['new_storage_wrapper'] = array(
|
||||
$form['new_storage_wrapper'] = [
|
||||
'#type' => 'container',
|
||||
'#states' => array(
|
||||
'!visible' => array(
|
||||
':input[name="new_storage_type"]' => array('value' => ''),
|
||||
),
|
||||
),
|
||||
);
|
||||
$form['new_storage_wrapper']['label'] = array(
|
||||
'#states' => [
|
||||
'!visible' => [
|
||||
':input[name="new_storage_type"]' => ['value' => ''],
|
||||
],
|
||||
],
|
||||
];
|
||||
$form['new_storage_wrapper']['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Label'),
|
||||
'#size' => 15,
|
||||
);
|
||||
];
|
||||
|
||||
$field_prefix = $this->config('field_ui.settings')->get('field_prefix');
|
||||
$form['new_storage_wrapper']['field_name'] = array(
|
||||
$form['new_storage_wrapper']['field_name'] = [
|
||||
'#type' => 'machine_name',
|
||||
// This field should stay LTR even for RTL languages.
|
||||
'#field_prefix' => '<span dir="ltr">' . $field_prefix,
|
||||
|
|
@ -181,44 +169,44 @@ class FieldStorageAddForm extends FormBase {
|
|||
// Calculate characters depending on the length of the field prefix
|
||||
// setting. Maximum length is 32.
|
||||
'#maxlength' => FieldStorageConfig::NAME_MAX_LENGTH - strlen($field_prefix),
|
||||
'#machine_name' => array(
|
||||
'source' => array('new_storage_wrapper', 'label'),
|
||||
'exists' => array($this, 'fieldNameExists'),
|
||||
),
|
||||
'#machine_name' => [
|
||||
'source' => ['new_storage_wrapper', 'label'],
|
||||
'exists' => [$this, 'fieldNameExists'],
|
||||
],
|
||||
'#required' => FALSE,
|
||||
);
|
||||
];
|
||||
|
||||
// Provide a separate label element for the "Re-use existing field" case
|
||||
// and place it outside the $form['add'] wrapper because those elements
|
||||
// are displayed inline.
|
||||
if ($existing_field_storage_options) {
|
||||
$form['existing_storage_label'] = array(
|
||||
$form['existing_storage_label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Label'),
|
||||
'#size' => 15,
|
||||
'#states' => array(
|
||||
'!visible' => array(
|
||||
':input[name="existing_storage_name"]' => array('value' => ''),
|
||||
),
|
||||
),
|
||||
);
|
||||
'#states' => [
|
||||
'!visible' => [
|
||||
':input[name="existing_storage_name"]' => ['value' => ''],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// Place the 'translatable' property as an explicit value so that contrib
|
||||
// modules can form_alter() the value for newly created fields. By default
|
||||
// we create field storage as translatable so it will be possible to enable
|
||||
// translation at field level.
|
||||
$form['translatable'] = array(
|
||||
$form['translatable'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Save and continue'),
|
||||
'#button_type' => 'primary',
|
||||
);
|
||||
];
|
||||
|
||||
$form['#attached']['library'][] = 'field_ui/drupal.field_ui';
|
||||
|
||||
|
|
@ -302,7 +290,7 @@ class FieldStorageAddForm extends FormBase {
|
|||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$error = FALSE;
|
||||
$values = $form_state->getValues();
|
||||
$destinations = array();
|
||||
$destinations = [];
|
||||
$entity_type = $this->entityManager->getDefinition($this->entityTypeId);
|
||||
|
||||
// Create new field.
|
||||
|
|
@ -333,7 +321,7 @@ class FieldStorageAddForm extends FormBase {
|
|||
|
||||
// Merge in preconfigured field storage options.
|
||||
if (isset($field_options['field_storage_config'])) {
|
||||
foreach (array('cardinality', 'settings') as $key) {
|
||||
foreach (['cardinality', 'settings'] as $key) {
|
||||
if (isset($field_options['field_storage_config'][$key])) {
|
||||
$field_storage_values[$key] = $field_options['field_storage_config'][$key];
|
||||
}
|
||||
|
|
@ -342,7 +330,7 @@ class FieldStorageAddForm extends FormBase {
|
|||
|
||||
// Merge in preconfigured field options.
|
||||
if (isset($field_options['field_config'])) {
|
||||
foreach (array('required', 'settings') as $key) {
|
||||
foreach (['required', 'settings'] as $key) {
|
||||
if (isset($field_options['field_config'][$key])) {
|
||||
$field_values[$key] = $field_options['field_config'][$key];
|
||||
}
|
||||
|
|
@ -364,19 +352,19 @@ class FieldStorageAddForm extends FormBase {
|
|||
|
||||
// Always show the field settings step, as the cardinality needs to be
|
||||
// configured for new fields.
|
||||
$route_parameters = array(
|
||||
$route_parameters = [
|
||||
'field_config' => $field->id(),
|
||||
) + FieldUI::getRouteBundleParameter($entity_type, $this->bundle);
|
||||
$destinations[] = array('route_name' => "entity.field_config.{$this->entityTypeId}_storage_edit_form", 'route_parameters' => $route_parameters);
|
||||
$destinations[] = array('route_name' => "entity.field_config.{$this->entityTypeId}_field_edit_form", 'route_parameters' => $route_parameters);
|
||||
$destinations[] = array('route_name' => "entity.{$this->entityTypeId}.field_ui_fields", 'route_parameters' => $route_parameters);
|
||||
] + FieldUI::getRouteBundleParameter($entity_type, $this->bundle);
|
||||
$destinations[] = ['route_name' => "entity.field_config.{$this->entityTypeId}_storage_edit_form", 'route_parameters' => $route_parameters];
|
||||
$destinations[] = ['route_name' => "entity.field_config.{$this->entityTypeId}_field_edit_form", 'route_parameters' => $route_parameters];
|
||||
$destinations[] = ['route_name' => "entity.{$this->entityTypeId}.field_ui_fields", 'route_parameters' => $route_parameters];
|
||||
|
||||
// Store new field information for any additional submit handlers.
|
||||
$form_state->set(['fields_added', '_add_new_field'], $values['field_name']);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$error = TRUE;
|
||||
drupal_set_message($this->t('There was a problem creating field %label: @message', array('%label' => $values['label'], '@message' => $e->getMessage())), 'error');
|
||||
drupal_set_message($this->t('There was a problem creating field %label: @message', ['%label' => $values['label'], '@message' => $e->getMessage()]), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -385,29 +373,29 @@ class FieldStorageAddForm extends FormBase {
|
|||
$field_name = $values['existing_storage_name'];
|
||||
|
||||
try {
|
||||
$field = $this->entityManager->getStorage('field_config')->create(array(
|
||||
$field = $this->entityManager->getStorage('field_config')->create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'bundle' => $this->bundle,
|
||||
'label' => $values['existing_storage_label'],
|
||||
));
|
||||
]);
|
||||
$field->save();
|
||||
|
||||
$this->configureEntityFormDisplay($field_name);
|
||||
$this->configureEntityViewDisplay($field_name);
|
||||
|
||||
$route_parameters = array(
|
||||
$route_parameters = [
|
||||
'field_config' => $field->id(),
|
||||
) + FieldUI::getRouteBundleParameter($entity_type, $this->bundle);
|
||||
$destinations[] = array('route_name' => "entity.field_config.{$this->entityTypeId}_field_edit_form", 'route_parameters' => $route_parameters);
|
||||
$destinations[] = array('route_name' => "entity.{$this->entityTypeId}.field_ui_fields", 'route_parameters' => $route_parameters);
|
||||
] + FieldUI::getRouteBundleParameter($entity_type, $this->bundle);
|
||||
$destinations[] = ['route_name' => "entity.field_config.{$this->entityTypeId}_field_edit_form", 'route_parameters' => $route_parameters];
|
||||
$destinations[] = ['route_name' => "entity.{$this->entityTypeId}.field_ui_fields", 'route_parameters' => $route_parameters];
|
||||
|
||||
// Store new field information for any additional submit handlers.
|
||||
$form_state->set(['fields_added', '_add_existing_field'], $field_name);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$error = TRUE;
|
||||
drupal_set_message($this->t('There was a problem creating field %label: @message', array('%label' => $values['label'], '@message' => $e->getMessage())), 'error');
|
||||
drupal_set_message($this->t('There was a problem creating field %label: @message', ['%label' => $values['label'], '@message' => $e->getMessage()]), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -464,7 +452,7 @@ class FieldStorageAddForm extends FormBase {
|
|||
* An array of existing field storages keyed by name.
|
||||
*/
|
||||
protected function getExistingFieldStorageOptions() {
|
||||
$options = array();
|
||||
$options = [];
|
||||
// Load the field_storages and build the list of options.
|
||||
$field_types = $this->fieldTypePluginManager->getDefinitions();
|
||||
foreach ($this->entityManager->getFieldStorageDefinitions($this->entityTypeId) as $field_name => $field_storage) {
|
||||
|
|
@ -478,10 +466,10 @@ class FieldStorageAddForm extends FormBase {
|
|||
&& !$field_storage->isLocked()
|
||||
&& empty($field_types[$field_type]['no_ui'])
|
||||
&& !in_array($this->bundle, $field_storage->getBundles(), TRUE)) {
|
||||
$options[$field_name] = $this->t('@type: @field', array(
|
||||
$options[$field_name] = $this->t('@type: @field', [
|
||||
'@type' => $field_types[$field_type]['label'],
|
||||
'@field' => $field_name,
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
asort($options);
|
||||
|
|
@ -505,14 +493,14 @@ class FieldStorageAddForm extends FormBase {
|
|||
protected function getExistingFieldLabels(array $field_names) {
|
||||
// Get all the fields corresponding to the given field storage names and
|
||||
// this entity type.
|
||||
$field_ids = $this->queryFactory->get('field_config')
|
||||
$field_ids = $this->entityManager->getStorage('field_config')->getQuery()
|
||||
->condition('entity_type', $this->entityTypeId)
|
||||
->condition('field_name', $field_names)
|
||||
->execute();
|
||||
$fields = $this->entityManager->getStorage('field_config')->loadMultiple($field_ids);
|
||||
|
||||
// Go through all the fields and use the label of the first encounter.
|
||||
$labels = array();
|
||||
$labels = [];
|
||||
foreach ($fields as $field) {
|
||||
if (!isset($labels[$field->getName()])) {
|
||||
$labels[$field->getName()] = $field->label();
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class FieldStorageConfigEditForm extends EntityForm {
|
|||
|
||||
$field_label = $form_state->get('field_config')->label();
|
||||
$form['#title'] = $field_label;
|
||||
$form['#prefix'] = '<p>' . $this->t('These settings apply to the %field field everywhere it is used. These settings impact the way that data is stored in the database and cannot be changed once data has been created.', array('%field' => $field_label)) . '</p>';
|
||||
$form['#prefix'] = '<p>' . $this->t('These settings apply to the %field field everywhere it is used. These settings impact the way that data is stored in the database and cannot be changed once data has been created.', ['%field' => $field_label]) . '</p>';
|
||||
|
||||
// See if data already exists for this field.
|
||||
// If so, prevent changes to the field settings.
|
||||
|
|
@ -73,17 +73,17 @@ class FieldStorageConfigEditForm extends EntityForm {
|
|||
// Add settings provided by the field module. The field module is
|
||||
// responsible for not returning settings that cannot be changed if
|
||||
// the field already has data.
|
||||
$form['settings'] = array(
|
||||
$form['settings'] = [
|
||||
'#weight' => -10,
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
];
|
||||
// Create an arbitrary entity object, so that we can have an instantiated
|
||||
// FieldItem.
|
||||
$ids = (object) array(
|
||||
$ids = (object) [
|
||||
'entity_type' => $form_state->get('entity_type_id'),
|
||||
'bundle' => $form_state->get('bundle'),
|
||||
'entity_id' => NULL
|
||||
);
|
||||
];
|
||||
$entity = _field_create_entity_from_ids($ids);
|
||||
$items = $entity->get($this->entity->getName());
|
||||
$item = $items->first() ?: $items->appendItem();
|
||||
|
|
@ -91,43 +91,43 @@ class FieldStorageConfigEditForm extends EntityForm {
|
|||
|
||||
// Build the configurable field values.
|
||||
$cardinality = $this->entity->getCardinality();
|
||||
$form['cardinality_container'] = array(
|
||||
$form['cardinality_container'] = [
|
||||
// Reset #parents so the additional container does not appear.
|
||||
'#parents' => array(),
|
||||
'#parents' => [],
|
||||
'#type' => 'fieldset',
|
||||
'#title' => $this->t('Allowed number of values'),
|
||||
'#attributes' => array('class' => array(
|
||||
'#attributes' => ['class' => [
|
||||
'container-inline',
|
||||
'fieldgroup',
|
||||
'form-composite'
|
||||
)),
|
||||
);
|
||||
$form['cardinality_container']['cardinality'] = array(
|
||||
]],
|
||||
];
|
||||
$form['cardinality_container']['cardinality'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Allowed number of values'),
|
||||
'#title_display' => 'invisible',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'number' => $this->t('Limited'),
|
||||
FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED => $this->t('Unlimited'),
|
||||
),
|
||||
],
|
||||
'#default_value' => ($cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) ? FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED : 'number',
|
||||
);
|
||||
$form['cardinality_container']['cardinality_number'] = array(
|
||||
];
|
||||
$form['cardinality_container']['cardinality_number'] = [
|
||||
'#type' => 'number',
|
||||
'#default_value' => $cardinality != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED ? $cardinality : 1,
|
||||
'#min' => 1,
|
||||
'#title' => $this->t('Limit'),
|
||||
'#title_display' => 'invisible',
|
||||
'#size' => 2,
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="cardinality"]' => array('value' => 'number'),
|
||||
),
|
||||
'disabled' => array(
|
||||
':input[name="cardinality"]' => array('value' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED),
|
||||
),
|
||||
),
|
||||
);
|
||||
'#states' => [
|
||||
'visible' => [
|
||||
':input[name="cardinality"]' => ['value' => 'number'],
|
||||
],
|
||||
'disabled' => [
|
||||
':input[name="cardinality"]' => ['value' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
@ -190,7 +190,7 @@ class FieldStorageConfigEditForm extends EntityForm {
|
|||
$field_label = $form_state->get('field_config')->label();
|
||||
try {
|
||||
$this->entity->save();
|
||||
drupal_set_message($this->t('Updated field %label field settings.', array('%label' => $field_label)));
|
||||
drupal_set_message($this->t('Updated field %label field settings.', ['%label' => $field_label]));
|
||||
$request = $this->getRequest();
|
||||
if (($destinations = $request->query->get('destinations')) && $next_destination = FieldUI::getNextDestination($destinations)) {
|
||||
$request->query->remove('destinations');
|
||||
|
|
@ -201,7 +201,7 @@ class FieldStorageConfigEditForm extends EntityForm {
|
|||
}
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
drupal_set_message($this->t('Attempt to update field %label failed: %message.', array('%label' => $field_label, '%message' => $e->getMessage())), 'error');
|
||||
drupal_set_message($this->t('Attempt to update field %label failed: %message.', ['%label' => $field_label, '%message' => $e->getMessage()]), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,15 +50,15 @@ class FieldUiLocalAction extends DeriverBase implements ContainerDeriverInterfac
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
$this->derivatives = array();
|
||||
$this->derivatives = [];
|
||||
|
||||
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
|
||||
if ($entity_type->get('field_ui_base_route')) {
|
||||
$this->derivatives["field_storage_config_add_$entity_type_id"] = array(
|
||||
$this->derivatives["field_storage_config_add_$entity_type_id"] = [
|
||||
'route_name' => "field_ui.field_storage_config_add_$entity_type_id",
|
||||
'title' => $this->t('Add field'),
|
||||
'appears_on' => array("entity.$entity_type_id.field_ui_fields"),
|
||||
);
|
||||
'appears_on' => ["entity.$entity_type_id.field_ui_fields"],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,46 +61,46 @@ class FieldUiLocalTask extends DeriverBase implements ContainerDeriverInterface
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
$this->derivatives = array();
|
||||
$this->derivatives = [];
|
||||
|
||||
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
|
||||
if ($entity_type->get('field_ui_base_route')) {
|
||||
$this->derivatives["overview_$entity_type_id"] = array(
|
||||
$this->derivatives["overview_$entity_type_id"] = [
|
||||
'route_name' => "entity.$entity_type_id.field_ui_fields",
|
||||
'weight' => 1,
|
||||
'title' => $this->t('Manage fields'),
|
||||
'base_route' => "entity.$entity_type_id.field_ui_fields",
|
||||
);
|
||||
];
|
||||
|
||||
// 'Manage form display' tab.
|
||||
$this->derivatives["form_display_overview_$entity_type_id"] = array(
|
||||
$this->derivatives["form_display_overview_$entity_type_id"] = [
|
||||
'route_name' => "entity.entity_form_display.$entity_type_id.default",
|
||||
'weight' => 2,
|
||||
'title' => $this->t('Manage form display'),
|
||||
'base_route' => "entity.$entity_type_id.field_ui_fields",
|
||||
);
|
||||
];
|
||||
|
||||
// 'Manage display' tab.
|
||||
$this->derivatives["display_overview_$entity_type_id"] = array(
|
||||
$this->derivatives["display_overview_$entity_type_id"] = [
|
||||
'route_name' => "entity.entity_view_display.$entity_type_id.default",
|
||||
'weight' => 3,
|
||||
'title' => $this->t('Manage display'),
|
||||
'base_route' => "entity.$entity_type_id.field_ui_fields",
|
||||
);
|
||||
];
|
||||
|
||||
// Field edit tab.
|
||||
$this->derivatives["field_edit_$entity_type_id"] = array(
|
||||
$this->derivatives["field_edit_$entity_type_id"] = [
|
||||
'route_name' => "entity.field_config.{$entity_type_id}_field_edit_form",
|
||||
'title' => $this->t('Edit'),
|
||||
'base_route' => "entity.field_config.{$entity_type_id}_field_edit_form",
|
||||
);
|
||||
];
|
||||
|
||||
// Field settings tab.
|
||||
$this->derivatives["field_storage_$entity_type_id"] = array(
|
||||
$this->derivatives["field_storage_$entity_type_id"] = [
|
||||
'route_name' => "entity.field_config.{$entity_type_id}_storage_edit_form",
|
||||
'title' => $this->t('Field settings'),
|
||||
'base_route' => "entity.field_config.{$entity_type_id}_field_edit_form",
|
||||
);
|
||||
];
|
||||
|
||||
// View and form modes secondary tabs.
|
||||
// The same base $path for the menu item (with a placeholder) can be
|
||||
|
|
@ -109,47 +109,47 @@ class FieldUiLocalTask extends DeriverBase implements ContainerDeriverInterface
|
|||
// modes available for customisation. So we define menu items for all
|
||||
// view modes, and use a route requirement to determine which ones are
|
||||
// actually visible for a given bundle.
|
||||
$this->derivatives['field_form_display_default_' . $entity_type_id] = array(
|
||||
$this->derivatives['field_form_display_default_' . $entity_type_id] = [
|
||||
'title' => 'Default',
|
||||
'route_name' => "entity.entity_form_display.$entity_type_id.default",
|
||||
'parent_id' => "field_ui.fields:form_display_overview_$entity_type_id",
|
||||
'weight' => -1,
|
||||
);
|
||||
$this->derivatives['field_display_default_' . $entity_type_id] = array(
|
||||
];
|
||||
$this->derivatives['field_display_default_' . $entity_type_id] = [
|
||||
'title' => 'Default',
|
||||
'route_name' => "entity.entity_view_display.$entity_type_id.default",
|
||||
'parent_id' => "field_ui.fields:display_overview_$entity_type_id",
|
||||
'weight' => -1,
|
||||
);
|
||||
];
|
||||
|
||||
// One local task for each form mode.
|
||||
$weight = 0;
|
||||
foreach ($this->entityManager->getFormModes($entity_type_id) as $form_mode => $form_mode_info) {
|
||||
$this->derivatives['field_form_display_' . $form_mode . '_' . $entity_type_id] = array(
|
||||
$this->derivatives['field_form_display_' . $form_mode . '_' . $entity_type_id] = [
|
||||
'title' => $form_mode_info['label'],
|
||||
'route_name' => "entity.entity_form_display.$entity_type_id.form_mode",
|
||||
'route_parameters' => array(
|
||||
'route_parameters' => [
|
||||
'form_mode_name' => $form_mode,
|
||||
),
|
||||
],
|
||||
'parent_id' => "field_ui.fields:form_display_overview_$entity_type_id",
|
||||
'weight' => $weight++,
|
||||
'cache_tags' => $this->entityManager->getDefinition('entity_form_display')->getListCacheTags(),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// One local task for each view mode.
|
||||
$weight = 0;
|
||||
foreach ($this->entityManager->getViewModes($entity_type_id) as $view_mode => $form_mode_info) {
|
||||
$this->derivatives['field_display_' . $view_mode . '_' . $entity_type_id] = array(
|
||||
$this->derivatives['field_display_' . $view_mode . '_' . $entity_type_id] = [
|
||||
'title' => $form_mode_info['label'],
|
||||
'route_name' => "entity.entity_view_display.$entity_type_id.view_mode",
|
||||
'route_parameters' => array(
|
||||
'route_parameters' => [
|
||||
'view_mode_name' => $view_mode,
|
||||
),
|
||||
],
|
||||
'parent_id' => "field_ui.fields:display_overview_$entity_type_id",
|
||||
'weight' => $weight++,
|
||||
'cache_tags' => $this->entityManager->getDefinition('entity_view_display')->getListCacheTags(),
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,16 +44,16 @@ class RouteSubscriber extends RouteSubscriberBase {
|
|||
|
||||
$options = $entity_route->getOptions();
|
||||
if ($bundle_entity_type = $entity_type->getBundleEntityType()) {
|
||||
$options['parameters'][$bundle_entity_type] = array(
|
||||
$options['parameters'][$bundle_entity_type] = [
|
||||
'type' => 'entity:' . $bundle_entity_type,
|
||||
);
|
||||
];
|
||||
}
|
||||
// Special parameter used to easily recognize all Field UI routes.
|
||||
$options['_field_ui'] = TRUE;
|
||||
|
||||
$defaults = array(
|
||||
$defaults = [
|
||||
'entity_type_id' => $entity_type_id,
|
||||
);
|
||||
];
|
||||
// If the entity type has no bundles and it doesn't use {bundle} in its
|
||||
// admin path, use the entity type.
|
||||
if (strpos($path, '{bundle}') === FALSE) {
|
||||
|
|
@ -62,95 +62,95 @@ class RouteSubscriber extends RouteSubscriberBase {
|
|||
|
||||
$route = new Route(
|
||||
"$path/fields/{field_config}",
|
||||
array(
|
||||
[
|
||||
'_entity_form' => 'field_config.edit',
|
||||
'_title_callback' => '\Drupal\field_ui\Form\FieldConfigEditForm::getTitle',
|
||||
) + $defaults,
|
||||
array('_entity_access' => 'field_config.update'),
|
||||
] + $defaults,
|
||||
['_entity_access' => 'field_config.update'],
|
||||
$options
|
||||
);
|
||||
$collection->add("entity.field_config.{$entity_type_id}_field_edit_form", $route);
|
||||
|
||||
$route = new Route(
|
||||
"$path/fields/{field_config}/storage",
|
||||
array('_entity_form' => 'field_storage_config.edit') + $defaults,
|
||||
array('_permission' => 'administer ' . $entity_type_id . ' fields'),
|
||||
['_entity_form' => 'field_storage_config.edit'] + $defaults,
|
||||
['_permission' => 'administer ' . $entity_type_id . ' fields'],
|
||||
$options
|
||||
);
|
||||
$collection->add("entity.field_config.{$entity_type_id}_storage_edit_form", $route);
|
||||
|
||||
$route = new Route(
|
||||
"$path/fields/{field_config}/delete",
|
||||
array('_entity_form' => 'field_config.delete') + $defaults,
|
||||
array('_entity_access' => 'field_config.delete'),
|
||||
['_entity_form' => 'field_config.delete'] + $defaults,
|
||||
['_entity_access' => 'field_config.delete'],
|
||||
$options
|
||||
);
|
||||
$collection->add("entity.field_config.{$entity_type_id}_field_delete_form", $route);
|
||||
|
||||
$route = new Route(
|
||||
"$path/fields",
|
||||
array(
|
||||
[
|
||||
'_controller' => '\Drupal\field_ui\Controller\FieldConfigListController::listing',
|
||||
'_title' => 'Manage fields',
|
||||
) + $defaults,
|
||||
array('_permission' => 'administer ' . $entity_type_id . ' fields'),
|
||||
] + $defaults,
|
||||
['_permission' => 'administer ' . $entity_type_id . ' fields'],
|
||||
$options
|
||||
);
|
||||
$collection->add("entity.{$entity_type_id}.field_ui_fields", $route);
|
||||
|
||||
$route = new Route(
|
||||
"$path/fields/add-field",
|
||||
array(
|
||||
[
|
||||
'_form' => '\Drupal\field_ui\Form\FieldStorageAddForm',
|
||||
'_title' => 'Add field',
|
||||
) + $defaults,
|
||||
array('_permission' => 'administer ' . $entity_type_id . ' fields'),
|
||||
] + $defaults,
|
||||
['_permission' => 'administer ' . $entity_type_id . ' fields'],
|
||||
$options
|
||||
);
|
||||
$collection->add("field_ui.field_storage_config_add_$entity_type_id", $route);
|
||||
|
||||
$route = new Route(
|
||||
"$path/form-display",
|
||||
array(
|
||||
[
|
||||
'_entity_form' => 'entity_form_display.edit',
|
||||
'_title' => 'Manage form display',
|
||||
'form_mode_name' => 'default',
|
||||
) + $defaults,
|
||||
array('_field_ui_form_mode_access' => 'administer ' . $entity_type_id . ' form display'),
|
||||
] + $defaults,
|
||||
['_field_ui_form_mode_access' => 'administer ' . $entity_type_id . ' form display'],
|
||||
$options
|
||||
);
|
||||
$collection->add("entity.entity_form_display.{$entity_type_id}.default", $route);
|
||||
|
||||
$route = new Route(
|
||||
"$path/form-display/{form_mode_name}",
|
||||
array(
|
||||
[
|
||||
'_entity_form' => 'entity_form_display.edit',
|
||||
'_title' => 'Manage form display',
|
||||
) + $defaults,
|
||||
array('_field_ui_form_mode_access' => 'administer ' . $entity_type_id . ' form display'),
|
||||
] + $defaults,
|
||||
['_field_ui_form_mode_access' => 'administer ' . $entity_type_id . ' form display'],
|
||||
$options
|
||||
);
|
||||
$collection->add("entity.entity_form_display.{$entity_type_id}.form_mode", $route);
|
||||
|
||||
$route = new Route(
|
||||
"$path/display",
|
||||
array(
|
||||
[
|
||||
'_entity_form' => 'entity_view_display.edit',
|
||||
'_title' => 'Manage display',
|
||||
'view_mode_name' => 'default',
|
||||
) + $defaults,
|
||||
array('_field_ui_view_mode_access' => 'administer ' . $entity_type_id . ' display'),
|
||||
] + $defaults,
|
||||
['_field_ui_view_mode_access' => 'administer ' . $entity_type_id . ' display'],
|
||||
$options
|
||||
);
|
||||
$collection->add("entity.entity_view_display.{$entity_type_id}.default", $route);
|
||||
|
||||
$route = new Route(
|
||||
"$path/display/{view_mode_name}",
|
||||
array(
|
||||
[
|
||||
'_entity_form' => 'entity_view_display.edit',
|
||||
'_title' => 'Manage display',
|
||||
) + $defaults,
|
||||
array('_field_ui_view_mode_access' => 'administer ' . $entity_type_id . ' display'),
|
||||
] + $defaults,
|
||||
['_field_ui_view_mode_access' => 'administer ' . $entity_type_id . ' display'],
|
||||
$options
|
||||
);
|
||||
$collection->add("entity.entity_view_display.{$entity_type_id}.view_mode", $route);
|
||||
|
|
@ -163,7 +163,7 @@ class RouteSubscriber extends RouteSubscriberBase {
|
|||
*/
|
||||
public static function getSubscribedEvents() {
|
||||
$events = parent::getSubscribedEvents();
|
||||
$events[RoutingEvents::ALTER] = array('onAlterRoutes', -100);
|
||||
$events[RoutingEvents::ALTER] = ['onAlterRoutes', -100];
|
||||
return $events;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,124 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\field_ui\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests the entity display modes UI.
|
||||
*
|
||||
* @group field_ui
|
||||
*/
|
||||
class EntityDisplayModeTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public static $modules = ['block', 'entity_test', 'field_ui'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('local_actions_block');
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the EntityViewMode user interface.
|
||||
*/
|
||||
public function testEntityViewModeUI() {
|
||||
// Test the listing page.
|
||||
$this->drupalGet('admin/structure/display-modes/view');
|
||||
$this->assertResponse(403);
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer display modes')));
|
||||
$this->drupalGet('admin/structure/display-modes/view');
|
||||
$this->assertResponse(200);
|
||||
$this->assertText(t('Add view mode'));
|
||||
$this->assertLinkByHref('admin/structure/display-modes/view/add');
|
||||
$this->assertLinkByHref('admin/structure/display-modes/view/add/entity_test');
|
||||
|
||||
$this->drupalGet('admin/structure/display-modes/view/add/entity_test_mulrev');
|
||||
$this->assertResponse(404);
|
||||
|
||||
$this->drupalGet('admin/structure/display-modes/view/add');
|
||||
$this->assertNoLink(t('Test entity - revisions and data table'), 'An entity type with no view builder cannot have view modes.');
|
||||
|
||||
// Test adding a view mode including dots in machine_name.
|
||||
$this->clickLink(t('Test entity'));
|
||||
$edit = array(
|
||||
'id' => strtolower($this->randomMachineName()) . '.' . strtolower($this->randomMachineName()),
|
||||
'label' => $this->randomString(),
|
||||
);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertRaw('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
|
||||
|
||||
// Test adding a view mode.
|
||||
$edit = array(
|
||||
'id' => strtolower($this->randomMachineName()),
|
||||
'label' => $this->randomString(),
|
||||
);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertRaw(t('Saved the %label view mode.', array('%label' => $edit['label'])));
|
||||
|
||||
// Test editing the view mode.
|
||||
$this->drupalGet('admin/structure/display-modes/view/manage/entity_test.' . $edit['id']);
|
||||
|
||||
// Test deleting the view mode.
|
||||
$this->clickLink(t('Delete'));
|
||||
$this->assertRaw(t('Are you sure you want to delete the view mode %label?', array('%label' => $edit['label'])));
|
||||
$this->drupalPostForm(NULL, NULL, t('Delete'));
|
||||
$this->assertRaw(t('The view mode %label has been deleted.', array('%label' => $edit['label'])));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the EntityFormMode user interface.
|
||||
*/
|
||||
public function testEntityFormModeUI() {
|
||||
// Test the listing page.
|
||||
$this->drupalGet('admin/structure/display-modes/form');
|
||||
$this->assertResponse(403);
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer display modes')));
|
||||
$this->drupalGet('admin/structure/display-modes/form');
|
||||
$this->assertResponse(200);
|
||||
$this->assertText(t('Add form mode'));
|
||||
$this->assertLinkByHref('admin/structure/display-modes/form/add');
|
||||
|
||||
$this->drupalGet('admin/structure/display-modes/form/add/entity_test_no_label');
|
||||
$this->assertResponse(404);
|
||||
|
||||
$this->drupalGet('admin/structure/display-modes/form/add');
|
||||
$this->assertNoLink(t('Entity Test without label'), 'An entity type with no form cannot have form modes.');
|
||||
|
||||
// Test adding a view mode including dots in machine_name.
|
||||
$this->clickLink(t('Test entity'));
|
||||
$edit = array(
|
||||
'id' => strtolower($this->randomMachineName()) . '.' . strtolower($this->randomMachineName()),
|
||||
'label' => $this->randomString(),
|
||||
);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertRaw('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
|
||||
|
||||
// Test adding a form mode.
|
||||
$edit = array(
|
||||
'id' => strtolower($this->randomMachineName()),
|
||||
'label' => $this->randomString(),
|
||||
);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertRaw(t('Saved the %label form mode.', array('%label' => $edit['label'])));
|
||||
|
||||
// Test editing the form mode.
|
||||
$this->drupalGet('admin/structure/display-modes/form/manage/entity_test.' . $edit['id']);
|
||||
|
||||
// Test deleting the form mode.
|
||||
$this->clickLink(t('Delete'));
|
||||
$this->assertRaw(t('Are you sure you want to delete the form mode %label?', array('%label' => $edit['label'])));
|
||||
$this->drupalPostForm(NULL, NULL, t('Delete'));
|
||||
$this->assertRaw(t('The form mode %label has been deleted.', array('%label' => $edit['label'])));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -21,14 +21,14 @@ class FieldUIDeleteTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'field_ui', 'field_test', 'block', 'field_test_views');
|
||||
public static $modules = ['node', 'field_ui', 'field_test', 'block', 'field_test_views'];
|
||||
|
||||
/**
|
||||
* Test views to enable
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public static $testViews = array('test_view_field_delete');
|
||||
public static $testViews = ['test_view_field_delete'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
@ -41,21 +41,21 @@ class FieldUIDeleteTest extends WebTestBase {
|
|||
$this->drupalPlaceBlock('page_title_block');
|
||||
|
||||
// Create a test user.
|
||||
$admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer users', 'administer account settings', 'administer user display', 'bypass node access'));
|
||||
$admin_user = $this->drupalCreateUser(['access content', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer users', 'administer account settings', 'administer user display', 'bypass node access']);
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that deletion removes field storages and fields as expected.
|
||||
*/
|
||||
function testDeleteField() {
|
||||
public function testDeleteField() {
|
||||
$field_label = $this->randomMachineName();
|
||||
$field_name_input = 'test';
|
||||
$field_name = 'field_test';
|
||||
|
||||
// Create an additional node type.
|
||||
$type_name1 = strtolower($this->randomMachineName(8)) . '_test';
|
||||
$type1 = $this->drupalCreateContentType(array('name' => $type_name1, 'type' => $type_name1));
|
||||
$type1 = $this->drupalCreateContentType(['name' => $type_name1, 'type' => $type_name1]);
|
||||
$type_name1 = $type1->id();
|
||||
|
||||
// Create a new field.
|
||||
|
|
@ -64,7 +64,7 @@ class FieldUIDeleteTest extends WebTestBase {
|
|||
|
||||
// Create an additional node type.
|
||||
$type_name2 = strtolower($this->randomMachineName(8)) . '_test';
|
||||
$type2 = $this->drupalCreateContentType(array('name' => $type_name2, 'type' => $type_name2));
|
||||
$type2 = $this->drupalCreateContentType(['name' => $type_name2, 'type' => $type_name2]);
|
||||
$type_name2 = $type2->id();
|
||||
|
||||
// Add a field to the second node type.
|
||||
|
|
@ -72,7 +72,7 @@ class FieldUIDeleteTest extends WebTestBase {
|
|||
$this->fieldUIAddExistingField($bundle_path2, $field_name, $field_label);
|
||||
|
||||
\Drupal::service('module_installer')->install(['views']);
|
||||
ViewTestData::createTestViews(get_class($this), array('field_test_views'));
|
||||
ViewTestData::createTestViews(get_class($this), ['field_test_views']);
|
||||
|
||||
// Check the config dependencies of the first field, the field storage must
|
||||
// not be shown as being deleted yet.
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\field_ui\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests indentation on Field UI.
|
||||
*
|
||||
* @group field_ui
|
||||
*/
|
||||
class FieldUIIndentationTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'field_ui', 'field_ui_test');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create a test user.
|
||||
$admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node display'));
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Create Basic page node type.
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
||||
|
||||
}
|
||||
|
||||
function testIndentation() {
|
||||
$this->drupalGet('admin/structure/types/manage/page/display');
|
||||
$this->assertRaw('js-indentation indentation');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\field_ui\Tests;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityFormMode;
|
||||
use Drupal\Core\Entity\Entity\EntityViewMode;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests the functionality of the Field UI route subscriber.
|
||||
*
|
||||
* @group field_ui
|
||||
*/
|
||||
class FieldUIRouteTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public static $modules = ['block', 'entity_test', 'field_ui'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalLogin($this->rootUser);
|
||||
$this->drupalPlaceBlock('local_tasks_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that entity types with bundles do not break following entity types.
|
||||
*/
|
||||
public function testFieldUIRoutes() {
|
||||
$this->drupalGet('entity_test_no_id/structure/entity_test/fields');
|
||||
$this->assertText('No fields are present yet.');
|
||||
|
||||
$this->drupalGet('admin/config/people/accounts/fields');
|
||||
$this->assertTitle('Manage fields | Drupal');
|
||||
$this->assertLocalTasks();
|
||||
|
||||
// Test manage display tabs and titles.
|
||||
$this->drupalGet('admin/config/people/accounts/display/compact');
|
||||
$this->assertResponse(403);
|
||||
|
||||
$this->drupalGet('admin/config/people/accounts/display');
|
||||
$this->assertTitle('Manage display | Drupal');
|
||||
$this->assertLocalTasks();
|
||||
|
||||
$edit = array('display_modes_custom[compact]' => TRUE);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->drupalGet('admin/config/people/accounts/display/compact');
|
||||
$this->assertTitle('Manage display | Drupal');
|
||||
$this->assertLocalTasks();
|
||||
|
||||
// Test manage form display tabs and titles.
|
||||
$this->drupalGet('admin/config/people/accounts/form-display/register');
|
||||
$this->assertResponse(403);
|
||||
|
||||
$this->drupalGet('admin/config/people/accounts/form-display');
|
||||
$this->assertTitle('Manage form display | Drupal');
|
||||
$this->assertLocalTasks();
|
||||
|
||||
$edit = array('display_modes_custom[register]' => TRUE);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertResponse(200);
|
||||
$this->drupalGet('admin/config/people/accounts/form-display/register');
|
||||
$this->assertTitle('Manage form display | Drupal');
|
||||
$this->assertLocalTasks();
|
||||
$this->assert(count($this->xpath('//ul/li[1]/a[contains(text(), :text)]', array(':text' => 'Default'))) == 1, 'Default secondary tab is in first position.');
|
||||
|
||||
// Create new view mode and verify it's available on the Manage Display
|
||||
// screen after enabling it.
|
||||
EntityViewMode::create(array(
|
||||
'id' => 'user.test',
|
||||
'label' => 'Test',
|
||||
'targetEntityType' => 'user',
|
||||
))->save();
|
||||
$this->container->get('router.builder')->rebuildIfNeeded();
|
||||
|
||||
$edit = array('display_modes_custom[test]' => TRUE);
|
||||
$this->drupalPostForm('admin/config/people/accounts/display', $edit, t('Save'));
|
||||
$this->assertLink('Test');
|
||||
|
||||
// Create new form mode and verify it's available on the Manage Form
|
||||
// Display screen after enabling it.
|
||||
EntityFormMode::create(array(
|
||||
'id' => 'user.test',
|
||||
'label' => 'Test',
|
||||
'targetEntityType' => 'user',
|
||||
))->save();
|
||||
$this->container->get('router.builder')->rebuildIfNeeded();
|
||||
|
||||
$edit = array('display_modes_custom[test]' => TRUE);
|
||||
$this->drupalPostForm('admin/config/people/accounts/form-display', $edit, t('Save'));
|
||||
$this->assertLink('Test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that local tasks exists.
|
||||
*/
|
||||
public function assertLocalTasks() {
|
||||
$this->assertLink('Settings');
|
||||
$this->assertLink('Manage fields');
|
||||
$this->assertLink('Manage display');
|
||||
$this->assertLink('Manage form display');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that admin routes are correctly marked as such.
|
||||
*/
|
||||
public function testAdminRoute() {
|
||||
$route = \Drupal::service('router.route_provider')->getRouteByName('entity.entity_test.field_ui_fields');
|
||||
$is_admin = \Drupal::service('router.admin_context')->isAdminRoute($route);
|
||||
$this->assertTrue($is_admin, 'Admin route correctly marked for "Manage fields" page.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -26,13 +26,13 @@ trait FieldUiTestTrait {
|
|||
* (optional) $edit parameter for drupalPostForm() on the third step ('Field
|
||||
* settings' form).
|
||||
*/
|
||||
public function fieldUIAddNewField($bundle_path, $field_name, $label = NULL, $field_type = 'test_field', array $storage_edit = array(), array $field_edit = array()) {
|
||||
public function fieldUIAddNewField($bundle_path, $field_name, $label = NULL, $field_type = 'test_field', array $storage_edit = [], array $field_edit = []) {
|
||||
$label = $label ?: $this->randomString();
|
||||
$initial_edit = array(
|
||||
$initial_edit = [
|
||||
'new_storage_type' => $field_type,
|
||||
'label' => $label,
|
||||
'field_name' => $field_name,
|
||||
);
|
||||
];
|
||||
|
||||
// Allow the caller to set a NULL path in case they navigated to the right
|
||||
// page before calling this method.
|
||||
|
|
@ -42,17 +42,17 @@ trait FieldUiTestTrait {
|
|||
|
||||
// First step: 'Add field' page.
|
||||
$this->drupalPostForm($bundle_path, $initial_edit, t('Save and continue'));
|
||||
$this->assertRaw(t('These settings apply to the %label field everywhere it is used.', array('%label' => $label)), 'Storage settings page was displayed.');
|
||||
$this->assertRaw(t('These settings apply to the %label field everywhere it is used.', ['%label' => $label]), 'Storage settings page was displayed.');
|
||||
// Test Breadcrumbs.
|
||||
$this->assertLink($label, 0, 'Field label is correct in the breadcrumb of the storage settings page.');
|
||||
|
||||
// Second step: 'Storage settings' form.
|
||||
$this->drupalPostForm(NULL, $storage_edit, t('Save field settings'));
|
||||
$this->assertRaw(t('Updated field %label field settings.', array('%label' => $label)), 'Redirected to field settings page.');
|
||||
$this->assertRaw(t('Updated field %label field settings.', ['%label' => $label]), 'Redirected to field settings page.');
|
||||
|
||||
// Third step: 'Field settings' form.
|
||||
$this->drupalPostForm(NULL, $field_edit, t('Save settings'));
|
||||
$this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), 'Redirected to "Manage fields" page.');
|
||||
$this->assertRaw(t('Saved %label configuration.', ['%label' => $label]), 'Redirected to "Manage fields" page.');
|
||||
|
||||
// Check that the field appears in the overview form.
|
||||
$this->assertFieldByXPath('//table[@id="field-overview"]//tr/td[1]', $label, 'Field was created and appears in the overview page.');
|
||||
|
|
@ -72,12 +72,12 @@ trait FieldUiTestTrait {
|
|||
* (optional) $edit parameter for drupalPostForm() on the second step
|
||||
* ('Field settings' form).
|
||||
*/
|
||||
public function fieldUIAddExistingField($bundle_path, $existing_storage_name, $label = NULL, array $field_edit = array()) {
|
||||
public function fieldUIAddExistingField($bundle_path, $existing_storage_name, $label = NULL, array $field_edit = []) {
|
||||
$label = $label ?: $this->randomString();
|
||||
$initial_edit = array(
|
||||
$initial_edit = [
|
||||
'existing_storage_name' => $existing_storage_name,
|
||||
'existing_storage_label' => $label,
|
||||
);
|
||||
];
|
||||
|
||||
// First step: 'Re-use existing field' on the 'Add field' page.
|
||||
$this->drupalPostForm("$bundle_path/fields/add-field", $initial_edit, t('Save and continue'));
|
||||
|
|
@ -90,7 +90,7 @@ trait FieldUiTestTrait {
|
|||
|
||||
// Second step: 'Field settings' form.
|
||||
$this->drupalPostForm(NULL, $field_edit, t('Save settings'));
|
||||
$this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), 'Redirected to "Manage fields" page.');
|
||||
$this->assertRaw(t('Saved %label configuration.', ['%label' => $label]), 'Redirected to "Manage fields" page.');
|
||||
|
||||
// Check that the field appears in the overview form.
|
||||
$this->assertFieldByXPath('//table[@id="field-overview"]//tr/td[1]', $label, 'Field was created and appears in the overview page.');
|
||||
|
|
@ -111,14 +111,14 @@ trait FieldUiTestTrait {
|
|||
public function fieldUIDeleteField($bundle_path, $field_name, $label, $bundle_label) {
|
||||
// Display confirmation form.
|
||||
$this->drupalGet("$bundle_path/fields/$field_name/delete");
|
||||
$this->assertRaw(t('Are you sure you want to delete the field %label', array('%label' => $label)), 'Delete confirmation was found.');
|
||||
$this->assertRaw(t('Are you sure you want to delete the field %label', ['%label' => $label]), 'Delete confirmation was found.');
|
||||
|
||||
// Test Breadcrumbs.
|
||||
$this->assertLink($label, 0, 'Field label is correct in the breadcrumb of the field delete page.');
|
||||
|
||||
// Submit confirmation form.
|
||||
$this->drupalPostForm(NULL, array(), t('Delete'));
|
||||
$this->assertRaw(t('The field %label has been deleted from the %type content type.', array('%label' => $label, '%type' => $bundle_label)), 'Delete message was found.');
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
$this->assertRaw(t('The field %label has been deleted from the %type content type.', ['%label' => $label, '%type' => $bundle_label]), 'Delete message was found.');
|
||||
|
||||
// Check that the field does not appear in the overview form.
|
||||
$this->assertNoFieldByXPath('//table[@id="field-overview"]//span[@class="label-field"]', $label, 'Field does not appear in the overview page.');
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\field_ui\Tests;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
|
|
@ -24,7 +25,7 @@ class ManageDisplayTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'field_ui', 'taxonomy', 'search', 'field_test', 'field_third_party_test', 'block');
|
||||
public static $modules = ['node', 'field_ui', 'taxonomy', 'search', 'field_test', 'field_third_party_test', 'block'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
@ -34,24 +35,24 @@ class ManageDisplayTest extends WebTestBase {
|
|||
$this->drupalPlaceBlock('system_breadcrumb_block');
|
||||
|
||||
// Create a test user.
|
||||
$admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer taxonomy', 'administer taxonomy_term fields', 'administer taxonomy_term display', 'administer users', 'administer account settings', 'administer user display', 'bypass node access'));
|
||||
$admin_user = $this->drupalCreateUser(['access content', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer taxonomy', 'administer taxonomy_term fields', 'administer taxonomy_term display', 'administer users', 'administer account settings', 'administer user display', 'bypass node access']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Create content type, with underscores.
|
||||
$type_name = strtolower($this->randomMachineName(8)) . '_test';
|
||||
$type = $this->drupalCreateContentType(array('name' => $type_name, 'type' => $type_name));
|
||||
$type = $this->drupalCreateContentType(['name' => $type_name, 'type' => $type_name]);
|
||||
$this->type = $type->id();
|
||||
|
||||
// Create a default vocabulary.
|
||||
$vocabulary = Vocabulary::create(array(
|
||||
$vocabulary = Vocabulary::create([
|
||||
'name' => $this->randomMachineName(),
|
||||
'description' => $this->randomMachineName(),
|
||||
'vid' => Unicode::strtolower($this->randomMachineName()),
|
||||
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
'help' => '',
|
||||
'nodes' => array('article' => 'article'),
|
||||
'nodes' => ['article' => 'article'],
|
||||
'weight' => mt_rand(0, 10),
|
||||
));
|
||||
]);
|
||||
$vocabulary->save();
|
||||
$this->vocabulary = $vocabulary->id();
|
||||
}
|
||||
|
|
@ -59,7 +60,7 @@ class ManageDisplayTest extends WebTestBase {
|
|||
/**
|
||||
* Tests formatter settings.
|
||||
*/
|
||||
function testFormatterUI() {
|
||||
public function testFormatterUI() {
|
||||
$manage_fields = 'admin/structure/types/manage/' . $this->type;
|
||||
$manage_display = $manage_fields . '/display';
|
||||
|
||||
|
|
@ -82,11 +83,11 @@ class ManageDisplayTest extends WebTestBase {
|
|||
$this->assertText("$setting_name: $setting_value", 'The expected summary is displayed.');
|
||||
|
||||
// Check whether formatter weights are respected.
|
||||
$result = $this->xpath('//select[@id=:id]/option', array(':id' => 'edit-fields-field-test-type'));
|
||||
$result = $this->xpath('//select[@id=:id]/option', [':id' => 'edit-fields-field-test-type']);
|
||||
$options = array_map(function($item) {
|
||||
return (string) $item->attributes()->value[0];
|
||||
}, $result);
|
||||
$expected_options = array (
|
||||
$expected_options = [
|
||||
'field_no_settings',
|
||||
'field_empty_test',
|
||||
'field_empty_setting',
|
||||
|
|
@ -94,13 +95,32 @@ class ManageDisplayTest extends WebTestBase {
|
|||
'field_test_multiple',
|
||||
'field_test_with_prepare_view',
|
||||
'field_test_applicable',
|
||||
'hidden',
|
||||
);
|
||||
];
|
||||
$this->assertEqual($options, $expected_options, 'The expected formatter ordering is respected.');
|
||||
|
||||
// Ensure that fields can be hidden directly by changing the region.
|
||||
$this->drupalGet($manage_display);
|
||||
$this->assertFieldByName('fields[field_test][region]', 'content');
|
||||
$edit = ['fields[field_test][region]' => 'hidden'];
|
||||
$this->drupalPostForm($manage_display, $edit, t('Save'));
|
||||
$this->assertFieldByName('fields[field_test][region]', 'hidden');
|
||||
$display = EntityViewDisplay::load("node.{$this->type}.default");
|
||||
$this->assertNull($display->getComponent('field_test'));
|
||||
|
||||
// Restore the field to the content region.
|
||||
$edit = [
|
||||
'fields[field_test][type]' => 'field_test_default',
|
||||
'fields[field_test][region]' => 'content',
|
||||
];
|
||||
$this->drupalPostForm($manage_display, $edit, t('Save'));
|
||||
|
||||
// Change the formatter and check that the summary is updated.
|
||||
$edit = array('fields[field_test][type]' => 'field_test_multiple', 'refresh_rows' => 'field_test');
|
||||
$this->drupalPostAjaxForm(NULL, $edit, array('op' => t('Refresh')));
|
||||
$edit = [
|
||||
'fields[field_test][type]' => 'field_test_multiple',
|
||||
'fields[field_test][region]' => 'content',
|
||||
'refresh_rows' => 'field_test'
|
||||
];
|
||||
$this->drupalPostAjaxForm(NULL, $edit, ['op' => t('Refresh')]);
|
||||
$format = 'field_test_multiple';
|
||||
$default_settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($format);
|
||||
$setting_name = key($default_settings);
|
||||
|
|
@ -109,7 +129,7 @@ class ManageDisplayTest extends WebTestBase {
|
|||
$this->assertText("$setting_name: $setting_value", 'The expected summary is displayed.');
|
||||
|
||||
// Submit the form and check that the display is updated.
|
||||
$this->drupalPostForm(NULL, array(), t('Save'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
$display = entity_get_display('node', $this->type, 'default');
|
||||
$display_options = $display->getComponent('field_test');
|
||||
$current_format = $display_options['type'];
|
||||
|
|
@ -122,17 +142,17 @@ class ManageDisplayTest extends WebTestBase {
|
|||
|
||||
// Click on the formatter settings button to open the formatter settings
|
||||
// form.
|
||||
$this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
|
||||
$this->drupalPostAjaxForm(NULL, [], "field_test_settings_edit");
|
||||
|
||||
// Assert that the field added in
|
||||
// field_test_field_formatter_third_party_settings_form() is present.
|
||||
$fieldname = 'fields[field_test][settings_edit_form][third_party_settings][field_third_party_test][field_test_field_formatter_third_party_settings_form]';
|
||||
$this->assertField($fieldname, 'The field added in hook_field_formatter_third_party_settings_form() is present on the settings form.');
|
||||
$edit = array($fieldname => 'foo');
|
||||
$edit = [$fieldname => 'foo'];
|
||||
$this->drupalPostAjaxForm(NULL, $edit, "field_test_plugin_settings_update");
|
||||
|
||||
// Save the form to save the third party settings.
|
||||
$this->drupalPostForm(NULL, array(), t('Save'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
\Drupal::entityManager()->clearCachedFieldDefinitions();
|
||||
$id = 'node.' . $this->type . '.default';
|
||||
|
|
@ -143,35 +163,42 @@ class ManageDisplayTest extends WebTestBase {
|
|||
$this->assertTrue(in_array('field_third_party_test', $display->calculateDependencies()->getDependencies()['module']), 'The display has a dependency on field_third_party_test module.');
|
||||
|
||||
// Confirm that the third party settings are not updated on the settings form.
|
||||
$this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
|
||||
$this->drupalPostAjaxForm(NULL, [], "field_test_settings_edit");
|
||||
$this->assertFieldByName($fieldname, '');
|
||||
|
||||
// Test the empty setting formatter.
|
||||
$edit = array('fields[field_test][type]' => 'field_empty_setting');
|
||||
$edit = [
|
||||
'fields[field_test][type]' => 'field_empty_setting',
|
||||
'fields[field_test][region]' => 'content',
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertNoText('Default empty setting now has a value.');
|
||||
$this->assertFieldById('edit-fields-field-test-settings-edit');
|
||||
$this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
|
||||
$this->drupalPostAjaxForm(NULL, [], "field_test_settings_edit");
|
||||
$fieldname = 'fields[field_test][settings_edit_form][settings][field_empty_setting]';
|
||||
$edit = array($fieldname => 'non empty setting');
|
||||
$edit = [$fieldname => 'non empty setting'];
|
||||
$this->drupalPostAjaxForm(NULL, $edit, "field_test_plugin_settings_update");
|
||||
$this->assertText('Default empty setting now has a value.');
|
||||
|
||||
// Test the settings form behavior. An edit button should be present since
|
||||
// there are third party settings to configure.
|
||||
$edit = array('fields[field_test][type]' => 'field_no_settings', 'refresh_rows' => 'field_test');
|
||||
$this->drupalPostAjaxForm(NULL, $edit, array('op' => t('Refresh')));
|
||||
$edit = [
|
||||
'fields[field_test][type]' => 'field_no_settings',
|
||||
'fields[field_test][region]' => 'content',
|
||||
'refresh_rows' => 'field_test',
|
||||
];
|
||||
$this->drupalPostAjaxForm(NULL, $edit, ['op' => t('Refresh')]);
|
||||
$this->assertFieldByName('field_test_settings_edit');
|
||||
|
||||
// Make sure we can save the third party settings when there are no settings available
|
||||
$this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
|
||||
$this->drupalPostAjaxForm(NULL, [], "field_test_settings_edit");
|
||||
$this->drupalPostAjaxForm(NULL, $edit, "field_test_plugin_settings_update");
|
||||
|
||||
// When a module providing third-party settings to a formatter (or widget)
|
||||
// is uninstalled, the formatter remains enabled but the provided settings,
|
||||
// together with the corresponding form elements, are removed from the
|
||||
// display component.
|
||||
\Drupal::service('module_installer')->uninstall(array('field_third_party_test'));
|
||||
\Drupal::service('module_installer')->uninstall(['field_third_party_test']);
|
||||
|
||||
// Ensure the button is still there after the module has been disabled.
|
||||
$this->drupalGet($manage_display);
|
||||
|
|
@ -179,7 +206,7 @@ class ManageDisplayTest extends WebTestBase {
|
|||
$this->assertFieldByName('field_test_settings_edit');
|
||||
|
||||
// Ensure that third-party form elements are not present anymore.
|
||||
$this->drupalPostAjaxForm(NULL, array(), 'field_test_settings_edit');
|
||||
$this->drupalPostAjaxForm(NULL, [], 'field_test_settings_edit');
|
||||
$fieldname = 'fields[field_test][settings_edit_form][third_party_settings][field_third_party_test][field_test_field_formatter_third_party_settings_form]';
|
||||
$this->assertNoField($fieldname);
|
||||
|
||||
|
|
@ -218,20 +245,23 @@ class ManageDisplayTest extends WebTestBase {
|
|||
$this->assertText("$setting_name: $setting_value", 'The expected summary is displayed.');
|
||||
|
||||
// Check whether widget weights are respected.
|
||||
$result = $this->xpath('//select[@id=:id]/option', array(':id' => 'edit-fields-field-test-type'));
|
||||
$result = $this->xpath('//select[@id=:id]/option', [':id' => 'edit-fields-field-test-type']);
|
||||
$options = array_map(function($item) {
|
||||
return (string) $item->attributes()->value[0];
|
||||
}, $result);
|
||||
$expected_options = array (
|
||||
$expected_options = [
|
||||
'test_field_widget',
|
||||
'test_field_widget_multiple',
|
||||
'hidden',
|
||||
);
|
||||
];
|
||||
$this->assertEqual($options, $expected_options, 'The expected widget ordering is respected.');
|
||||
|
||||
// Change the widget and check that the summary is updated.
|
||||
$edit = array('fields[field_test][type]' => 'test_field_widget_multiple', 'refresh_rows' => 'field_test');
|
||||
$this->drupalPostAjaxForm(NULL, $edit, array('op' => t('Refresh')));
|
||||
$edit = [
|
||||
'fields[field_test][type]' => 'test_field_widget_multiple',
|
||||
'fields[field_test][region]' => 'content',
|
||||
'refresh_rows' => 'field_test',
|
||||
];
|
||||
$this->drupalPostAjaxForm(NULL, $edit, ['op' => t('Refresh')]);
|
||||
$widget_type = 'test_field_widget_multiple';
|
||||
$default_settings = \Drupal::service('plugin.manager.field.widget')->getDefaultSettings($widget_type);
|
||||
$setting_name = key($default_settings);
|
||||
|
|
@ -240,7 +270,7 @@ class ManageDisplayTest extends WebTestBase {
|
|||
$this->assertText("$setting_name: $setting_value", 'The expected summary is displayed.');
|
||||
|
||||
// Submit the form and check that the display is updated.
|
||||
$this->drupalPostForm(NULL, array(), t('Save'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
$display = entity_get_form_display('node', $this->type, 'default');
|
||||
$display_options = $display->getComponent('field_test');
|
||||
$current_widget = $display_options['type'];
|
||||
|
|
@ -252,26 +282,26 @@ class ManageDisplayTest extends WebTestBase {
|
|||
$this->assertText('field_test_field_widget_settings_summary_alter');
|
||||
|
||||
// Click on the widget settings button to open the widget settings form.
|
||||
$this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
|
||||
$this->drupalPostAjaxForm(NULL, [], "field_test_settings_edit");
|
||||
|
||||
// Assert that the field added in
|
||||
// field_test_field_widget_third_party_settings_form() is present.
|
||||
$fieldname = 'fields[field_test][settings_edit_form][third_party_settings][field_third_party_test][field_test_widget_third_party_settings_form]';
|
||||
$this->assertField($fieldname, 'The field added in hook_field_widget_third_party_settings_form() is present on the settings form.');
|
||||
$edit = array($fieldname => 'foo');
|
||||
$edit = [$fieldname => 'foo'];
|
||||
$this->drupalPostAjaxForm(NULL, $edit, "field_test_plugin_settings_update");
|
||||
|
||||
// Save the form to save the third party settings.
|
||||
$this->drupalPostForm(NULL, array(), t('Save'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
\Drupal::entityManager()->clearCachedFieldDefinitions();
|
||||
$storage = $this->container->get('entity_type.manager')->getStorage('entity_form_display');
|
||||
$storage->resetCache(array('node.' . $this->type . '.default'));
|
||||
$storage->resetCache(['node.' . $this->type . '.default']);
|
||||
$display = $storage->load('node.' . $this->type . '.default');
|
||||
$this->assertEqual($display->getRenderer('field_test')->getThirdPartySetting('field_third_party_test', 'field_test_widget_third_party_settings_form'), 'foo');
|
||||
$this->assertTrue(in_array('field_third_party_test', $display->calculateDependencies()->getDependencies()['module']), 'Form display does not have a dependency on field_third_party_test module.');
|
||||
|
||||
// Confirm that the third party settings are not updated on the settings form.
|
||||
$this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
|
||||
$this->drupalPostAjaxForm(NULL, [], "field_test_settings_edit");
|
||||
$this->assertFieldByName($fieldname, '');
|
||||
|
||||
// Creates a new field that can not be used with the multiple formatter.
|
||||
|
|
@ -282,14 +312,22 @@ class ManageDisplayTest extends WebTestBase {
|
|||
$this->drupalGet($manage_display);
|
||||
|
||||
// Checks if the select elements contain the specified options.
|
||||
$this->assertFieldSelectOptions('fields[field_test][type]', array('test_field_widget', 'test_field_widget_multiple', 'hidden'));
|
||||
$this->assertFieldSelectOptions('fields[field_onewidgetfield][type]', array('test_field_widget', 'hidden'));
|
||||
$this->assertFieldSelectOptions('fields[field_test][type]', ['test_field_widget', 'test_field_widget_multiple']);
|
||||
$this->assertFieldSelectOptions('fields[field_onewidgetfield][type]', ['test_field_widget']);
|
||||
|
||||
// Ensure that fields can be hidden directly by changing the region.
|
||||
$this->assertFieldByName('fields[field_test][region]', 'content');
|
||||
$edit = ['fields[field_test][region]' => 'hidden'];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertFieldByName('fields[field_test][region]', 'hidden');
|
||||
$display = EntityFormDisplay::load("node.{$this->type}.default");
|
||||
$this->assertNull($display->getComponent('field_test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests switching view modes to use custom or 'default' settings'.
|
||||
*/
|
||||
function testViewModeCustom() {
|
||||
public function testViewModeCustom() {
|
||||
// Create a field, and a node with some data for the field.
|
||||
$this->fieldUIAddNewField('admin/structure/types/manage/' . $this->type, 'test', 'Test field');
|
||||
\Drupal::entityManager()->clearCachedFieldDefinitions();
|
||||
|
|
@ -297,20 +335,20 @@ class ManageDisplayTest extends WebTestBase {
|
|||
// to appear in a rendered node other than as part of the field being tested
|
||||
// (for example, unlikely to be part of the "Submitted by ... on ..." line).
|
||||
$value = 12345;
|
||||
$settings = array(
|
||||
$settings = [
|
||||
'type' => $this->type,
|
||||
'field_test' => array(array('value' => $value)),
|
||||
);
|
||||
'field_test' => [['value' => $value]],
|
||||
];
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
|
||||
// Gather expected output values with the various formatters.
|
||||
$formatter_plugin_manager = \Drupal::service('plugin.manager.field.formatter');
|
||||
$field_test_default_settings = $formatter_plugin_manager->getDefaultSettings('field_test_default');
|
||||
$field_test_with_prepare_view_settings = $formatter_plugin_manager->getDefaultSettings('field_test_with_prepare_view');
|
||||
$output = array(
|
||||
$output = [
|
||||
'field_test_default' => $field_test_default_settings['test_formatter_setting'] . '|' . $value,
|
||||
'field_test_with_prepare_view' => $field_test_with_prepare_view_settings['test_formatter_setting_additional'] . '|' . $value . '|' . ($value + 1),
|
||||
);
|
||||
];
|
||||
|
||||
// Check that the field is displayed with the default formatter in 'rss'
|
||||
// mode (uses 'default'), and hidden in 'teaser' mode (uses custom settings).
|
||||
|
|
@ -319,39 +357,40 @@ class ManageDisplayTest extends WebTestBase {
|
|||
|
||||
// Change formatter for 'default' mode, check that the field is displayed
|
||||
// accordingly in 'rss' mode.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'fields[field_test][type]' => 'field_test_with_prepare_view',
|
||||
);
|
||||
'fields[field_test][region]' => 'content',
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/' . $this->type . '/display', $edit, t('Save'));
|
||||
$this->assertNodeViewText($node, 'rss', $output['field_test_with_prepare_view'], "The field is displayed as expected in view modes that use 'default' settings.");
|
||||
|
||||
// Specialize the 'rss' mode, check that the field is displayed the same.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
"display_modes_custom[rss]" => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/' . $this->type . '/display', $edit, t('Save'));
|
||||
$this->assertNodeViewText($node, 'rss', $output['field_test_with_prepare_view'], "The field is displayed as expected in newly specialized 'rss' mode.");
|
||||
|
||||
// Set the field to 'hidden' in the view mode, check that the field is
|
||||
// hidden.
|
||||
$edit = array(
|
||||
'fields[field_test][type]' => 'hidden',
|
||||
);
|
||||
$edit = [
|
||||
'fields[field_test][region]' => 'hidden',
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/' . $this->type . '/display/rss', $edit, t('Save'));
|
||||
$this->assertNodeViewNoText($node, 'rss', $value, "The field is hidden in 'rss' mode.");
|
||||
|
||||
// Set the view mode back to 'default', check that the field is displayed
|
||||
// accordingly.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
"display_modes_custom[rss]" => FALSE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/' . $this->type . '/display', $edit, t('Save'));
|
||||
$this->assertNodeViewText($node, 'rss', $output['field_test_with_prepare_view'], "The field is displayed as expected when 'rss' mode is set back to 'default' settings.");
|
||||
|
||||
// Specialize the view mode again.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
"display_modes_custom[rss]" => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/' . $this->type . '/display', $edit, t('Save'));
|
||||
// Check that the previous settings for the view mode have been kept.
|
||||
$this->assertNodeViewNoText($node, 'rss', $value, "The previous settings are kept when 'rss' mode is specialized again.");
|
||||
|
|
@ -371,39 +410,39 @@ class ManageDisplayTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that fields with no explicit display settings do not break.
|
||||
*/
|
||||
function testNonInitializedFields() {
|
||||
public function testNonInitializedFields() {
|
||||
// Create a test field.
|
||||
$this->fieldUIAddNewField('admin/structure/types/manage/' . $this->type, 'test', 'Test');
|
||||
|
||||
// Check that the field appears as 'hidden' on the 'Manage display' page
|
||||
// for the 'teaser' mode.
|
||||
$this->drupalGet('admin/structure/types/manage/' . $this->type . '/display/teaser');
|
||||
$this->assertFieldByName('fields[field_test][type]', 'hidden', 'The field is displayed as \'hidden \'.');
|
||||
$this->assertFieldByName('fields[field_test][region]', 'hidden', 'The field is displayed as \'hidden \'.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests hiding the view modes fieldset when there's only one available.
|
||||
*/
|
||||
function testSingleViewMode() {
|
||||
public function testSingleViewMode() {
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary . '/display');
|
||||
$this->assertNoText('Use custom display settings for the following view modes', 'Custom display settings fieldset found.');
|
||||
|
||||
// This may not trigger a notice when 'view_modes_custom' isn't available.
|
||||
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary . '/overview/display', array(), t('Save'));
|
||||
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary . '/overview/display', [], t('Save'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a message is shown when there are no fields.
|
||||
*/
|
||||
function testNoFieldsDisplayOverview() {
|
||||
public function testNoFieldsDisplayOverview() {
|
||||
// Create a fresh content type without any fields.
|
||||
NodeType::create(array(
|
||||
NodeType::create([
|
||||
'type' => 'no_fields',
|
||||
'name' => 'No fields',
|
||||
))->save();
|
||||
])->save();
|
||||
|
||||
$this->drupalGet('admin/structure/types/manage/no_fields/display');
|
||||
$this->assertRaw(t('There are no fields yet added. You can add new fields on the <a href=":link">Manage fields</a> page.', array(':link' => \Drupal::url('entity.node.field_ui_fields', array('node_type' => 'no_fields')))));
|
||||
$this->assertRaw(t('There are no fields yet added. You can add new fields on the <a href=":link">Manage fields</a> page.', [':link' => \Drupal::url('entity.node.field_ui_fields', ['node_type' => 'no_fields'])]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -421,7 +460,7 @@ class ManageDisplayTest extends WebTestBase {
|
|||
* @return
|
||||
* TRUE on pass, FALSE on fail.
|
||||
*/
|
||||
function assertNodeViewText(EntityInterface $node, $view_mode, $text, $message) {
|
||||
public function assertNodeViewText(EntityInterface $node, $view_mode, $text, $message) {
|
||||
return $this->assertNodeViewTextHelper($node, $view_mode, $text, $message, FALSE);
|
||||
}
|
||||
|
||||
|
|
@ -439,7 +478,7 @@ class ManageDisplayTest extends WebTestBase {
|
|||
* @return
|
||||
* TRUE on pass, FALSE on fail.
|
||||
*/
|
||||
function assertNodeViewNoText(EntityInterface $node, $view_mode, $text, $message) {
|
||||
public function assertNodeViewNoText(EntityInterface $node, $view_mode, $text, $message) {
|
||||
return $this->assertNodeViewTextHelper($node, $view_mode, $text, $message, TRUE);
|
||||
}
|
||||
|
||||
|
|
@ -463,7 +502,7 @@ class ManageDisplayTest extends WebTestBase {
|
|||
* @return
|
||||
* TRUE on pass, FALSE on fail.
|
||||
*/
|
||||
function assertNodeViewTextHelper(EntityInterface $node, $view_mode, $text, $message, $not_exists) {
|
||||
public function assertNodeViewTextHelper(EntityInterface $node, $view_mode, $text, $message, $not_exists) {
|
||||
// Make sure caches on the tester side are refreshed after changes
|
||||
// submitted on the tested side.
|
||||
\Drupal::entityManager()->clearCachedFieldDefinitions();
|
||||
|
|
@ -475,7 +514,7 @@ class ManageDisplayTest extends WebTestBase {
|
|||
$clone = clone $node;
|
||||
$element = node_view($clone, $view_mode);
|
||||
$output = \Drupal::service('renderer')->renderRoot($element);
|
||||
$this->verbose(t('Rendered node - view mode: @view_mode', array('@view_mode' => $view_mode)) . '<hr />' . $output);
|
||||
$this->verbose(t('Rendered node - view mode: @view_mode', ['@view_mode' => $view_mode]) . '<hr />' . $output);
|
||||
|
||||
// Assign content so that WebTestBase functions can be used.
|
||||
$this->setRawContent($output);
|
||||
|
|
@ -500,7 +539,7 @@ class ManageDisplayTest extends WebTestBase {
|
|||
* TRUE if the assertion succeeded, FALSE otherwise.
|
||||
*/
|
||||
protected function assertFieldSelectOptions($name, array $expected_options) {
|
||||
$xpath = $this->buildXPathQuery('//select[@name=:name]', array(':name' => $name));
|
||||
$xpath = $this->buildXPathQuery('//select[@name=:name]', [':name' => $name]);
|
||||
$fields = $this->xpath($xpath);
|
||||
if ($fields) {
|
||||
$field = $fields[0];
|
||||
|
|
@ -526,7 +565,7 @@ class ManageDisplayTest extends WebTestBase {
|
|||
* An array of option values as strings.
|
||||
*/
|
||||
protected function getAllOptionsList(\SimpleXMLElement $element) {
|
||||
$options = array();
|
||||
$options = [];
|
||||
// Add all options items.
|
||||
foreach ($element->option as $option) {
|
||||
$options[] = (string) $option['value'];
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class ManageFieldsTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'field_ui', 'field_test', 'taxonomy', 'image', 'block');
|
||||
public static $modules = ['node', 'field_ui', 'field_test', 'taxonomy', 'image', 'block'];
|
||||
|
||||
/**
|
||||
* The ID of the custom content type created for testing.
|
||||
|
|
@ -68,12 +68,12 @@ class ManageFieldsTest extends WebTestBase {
|
|||
$this->drupalPlaceBlock('page_title_block');
|
||||
|
||||
// Create a test user.
|
||||
$admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer taxonomy', 'administer taxonomy_term fields', 'administer taxonomy_term display', 'administer users', 'administer account settings', 'administer user display', 'bypass node access'));
|
||||
$admin_user = $this->drupalCreateUser(['access content', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer taxonomy', 'administer taxonomy_term fields', 'administer taxonomy_term display', 'administer users', 'administer account settings', 'administer user display', 'bypass node access']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Create content type, with underscores.
|
||||
$type_name = strtolower($this->randomMachineName(8)) . '_test';
|
||||
$type = $this->drupalCreateContentType(array('name' => $type_name, 'type' => $type_name));
|
||||
$type = $this->drupalCreateContentType(['name' => $type_name, 'type' => $type_name]);
|
||||
$this->contentType = $type->id();
|
||||
|
||||
// Create random field name with markup to test escaping.
|
||||
|
|
@ -82,22 +82,22 @@ class ManageFieldsTest extends WebTestBase {
|
|||
$this->fieldName = 'field_' . $this->fieldNameInput;
|
||||
|
||||
// Create Basic page and Article node types.
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
||||
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
|
||||
// Create a vocabulary named "Tags".
|
||||
$vocabulary = Vocabulary::create(array(
|
||||
$vocabulary = Vocabulary::create([
|
||||
'name' => 'Tags',
|
||||
'vid' => 'tags',
|
||||
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
));
|
||||
]);
|
||||
$vocabulary->save();
|
||||
|
||||
$handler_settings = array(
|
||||
'target_bundles' => array(
|
||||
$handler_settings = [
|
||||
'target_bundles' => [
|
||||
$vocabulary->id() => $vocabulary->id(),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$this->createEntityReferenceField('node', 'article', 'field_' . $vocabulary->id(), 'Tags', 'taxonomy_term', 'default', $handler_settings);
|
||||
|
||||
entity_get_form_display('node', 'article', 'default')
|
||||
|
|
@ -111,7 +111,7 @@ class ManageFieldsTest extends WebTestBase {
|
|||
* In order to act on the same fields, and not create the fields over and over
|
||||
* again the following tests create, update and delete the same fields.
|
||||
*/
|
||||
function testCRUDFields() {
|
||||
public function testCRUDFields() {
|
||||
$this->manageFieldsPage();
|
||||
$this->createField();
|
||||
$this->updateField();
|
||||
|
|
@ -128,19 +128,19 @@ class ManageFieldsTest extends WebTestBase {
|
|||
* @param string $type
|
||||
* (optional) The name of a content type.
|
||||
*/
|
||||
function manageFieldsPage($type = '') {
|
||||
public function manageFieldsPage($type = '') {
|
||||
$type = empty($type) ? $this->contentType : $type;
|
||||
$this->drupalGet('admin/structure/types/manage/' . $type . '/fields');
|
||||
// Check all table columns.
|
||||
$table_headers = array(
|
||||
$table_headers = [
|
||||
t('Label'),
|
||||
t('Machine name'),
|
||||
t('Field type'),
|
||||
t('Operations'),
|
||||
);
|
||||
];
|
||||
foreach ($table_headers as $table_header) {
|
||||
// We check that the label appear in the table headings.
|
||||
$this->assertRaw($table_header . '</th>', format_string('%table_header table header was found.', array('%table_header' => $table_header)));
|
||||
$this->assertRaw($table_header . '</th>', format_string('%table_header table header was found.', ['%table_header' => $table_header]));
|
||||
}
|
||||
|
||||
// Test the "Add field" action link.
|
||||
|
|
@ -178,7 +178,7 @@ class ManageFieldsTest extends WebTestBase {
|
|||
* @todo Assert properties can bet set in the form and read back in
|
||||
* $field_storage and $fields.
|
||||
*/
|
||||
function createField() {
|
||||
public function createField() {
|
||||
// Create a test field.
|
||||
$this->fieldUIAddNewField('admin/structure/types/manage/' . $this->contentType, $this->fieldNameInput, $this->fieldLabel);
|
||||
}
|
||||
|
|
@ -186,7 +186,7 @@ class ManageFieldsTest extends WebTestBase {
|
|||
/**
|
||||
* Tests editing an existing field.
|
||||
*/
|
||||
function updateField() {
|
||||
public function updateField() {
|
||||
$field_id = 'node.' . $this->contentType . '.' . $this->fieldName;
|
||||
// Go to the field edit page.
|
||||
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/' . $field_id . '/storage');
|
||||
|
|
@ -194,16 +194,16 @@ class ManageFieldsTest extends WebTestBase {
|
|||
|
||||
// Populate the field settings with new settings.
|
||||
$string = 'updated dummy test string';
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'settings[test_field_storage_setting]' => $string,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save field settings'));
|
||||
|
||||
// Go to the field edit page.
|
||||
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/' . $field_id);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'settings[test_field_setting]' => $string,
|
||||
);
|
||||
];
|
||||
$this->assertText(t('Default value'), 'Default value heading is shown');
|
||||
$this->drupalPostForm(NULL, $edit, t('Save settings'));
|
||||
|
||||
|
|
@ -217,7 +217,7 @@ class ManageFieldsTest extends WebTestBase {
|
|||
/**
|
||||
* Tests adding an existing field in another content type.
|
||||
*/
|
||||
function addExistingField() {
|
||||
public function addExistingField() {
|
||||
// Check "Re-use existing field" appears.
|
||||
$this->drupalGet('admin/structure/types/manage/page/fields/add-field');
|
||||
$this->assertRaw(t('Re-use an existing field'), '"Re-use existing field" was found.');
|
||||
|
|
@ -226,7 +226,7 @@ class ManageFieldsTest extends WebTestBase {
|
|||
// do not show up in the "Re-use existing field" list.
|
||||
$this->assertFalse($this->xpath('//select[@id="edit-existing-storage-name"]//option[@value="comment"]'), 'The list of options respects entity type restrictions.');
|
||||
// Validate the FALSE assertion above by also testing a valid one.
|
||||
$this->assertTrue($this->xpath('//select[@id="edit-existing-storage-name"]//option[@value=:field_name]', array(':field_name' => $this->fieldName)), 'The list of options shows a valid option.');
|
||||
$this->assertTrue($this->xpath('//select[@id="edit-existing-storage-name"]//option[@value=:field_name]', [':field_name' => $this->fieldName]), 'The list of options shows a valid option.');
|
||||
|
||||
// Add a new field based on an existing field.
|
||||
$this->fieldUIAddExistingField("admin/structure/types/manage/page", $this->fieldName, $this->fieldLabel . '_2');
|
||||
|
|
@ -238,23 +238,23 @@ class ManageFieldsTest extends WebTestBase {
|
|||
* We do not test if the number can be submitted with anything else than a
|
||||
* numeric value. That is tested already in FormTest::testNumber().
|
||||
*/
|
||||
function cardinalitySettings() {
|
||||
public function cardinalitySettings() {
|
||||
$field_edit_path = 'admin/structure/types/manage/article/fields/node.article.body/storage';
|
||||
|
||||
// Assert the cardinality other field cannot be empty when cardinality is
|
||||
// set to 'number'.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'cardinality' => 'number',
|
||||
'cardinality_number' => '',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($field_edit_path, $edit, t('Save field settings'));
|
||||
$this->assertText('Number of values is required.');
|
||||
|
||||
// Submit a custom number.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'cardinality' => 'number',
|
||||
'cardinality_number' => 6,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($field_edit_path, $edit, t('Save field settings'));
|
||||
$this->assertText('Updated field Body field settings.');
|
||||
$this->drupalGet($field_edit_path);
|
||||
|
|
@ -285,9 +285,9 @@ class ManageFieldsTest extends WebTestBase {
|
|||
$this->drupalPostForm('node/add/article', $edit, 'Save');
|
||||
|
||||
// Set to unlimited.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($field_edit_path, $edit, t('Save field settings'));
|
||||
$this->assertText('Updated field Body field settings.');
|
||||
$this->drupalGet($field_edit_path);
|
||||
|
|
@ -340,7 +340,7 @@ class ManageFieldsTest extends WebTestBase {
|
|||
// Delete all the body field instances.
|
||||
$this->drupalGet('admin/structure/types/manage/' . $node_type . '/fields/node.' . $node_type . '.' . $this->fieldName);
|
||||
$this->clickLink(t('Delete'));
|
||||
$this->drupalPostForm(NULL, array(), t('Delete'));
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
}
|
||||
// Check "Re-use existing field" appears.
|
||||
$this->drupalGet('admin/structure/types/manage/page/fields/add-field');
|
||||
|
|
@ -364,7 +364,7 @@ class ManageFieldsTest extends WebTestBase {
|
|||
* @param $entity_type
|
||||
* The entity type for the field.
|
||||
*/
|
||||
function assertFieldSettings($bundle, $field_name, $string = 'dummy test string', $entity_type = 'node') {
|
||||
public function assertFieldSettings($bundle, $field_name, $string = 'dummy test string', $entity_type = 'node') {
|
||||
// Assert field storage settings.
|
||||
$field_storage = FieldStorageConfig::loadByName($entity_type, $field_name);
|
||||
$this->assertTrue($field_storage->getSetting('test_field_storage_setting') == $string, 'Field storage settings were found.');
|
||||
|
|
@ -377,7 +377,7 @@ class ManageFieldsTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that the 'field_prefix' setting works on Field UI.
|
||||
*/
|
||||
function testFieldPrefix() {
|
||||
public function testFieldPrefix() {
|
||||
// Change default field prefix.
|
||||
$field_prefix = strtolower($this->randomMachineName(10));
|
||||
$this->config('field_ui.settings')->set('field_prefix', $field_prefix)->save();
|
||||
|
|
@ -387,35 +387,35 @@ class ManageFieldsTest extends WebTestBase {
|
|||
$field_exceed_max_length_input = $this->randomMachineName(23);
|
||||
|
||||
// Try to create the field.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'label' => $field_exceed_max_length_label,
|
||||
'field_name' => $field_exceed_max_length_input,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/' . $this->contentType . '/fields/add-field', $edit, t('Save and continue'));
|
||||
$this->assertText('Machine-readable name cannot be longer than 22 characters but is currently 23 characters long.');
|
||||
|
||||
// Create a valid field.
|
||||
$this->fieldUIAddNewField('admin/structure/types/manage/' . $this->contentType, $this->fieldNameInput, $this->fieldLabel);
|
||||
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/node.' . $this->contentType . '.' . $field_prefix . $this->fieldNameInput);
|
||||
$this->assertText(format_string('@label settings for @type', array('@label' => $this->fieldLabel, '@type' => $this->contentType)));
|
||||
$this->assertText(format_string('@label settings for @type', ['@label' => $this->fieldLabel, '@type' => $this->contentType]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that default value is correctly validated and saved.
|
||||
*/
|
||||
function testDefaultValue() {
|
||||
public function testDefaultValue() {
|
||||
// Create a test field storage and field.
|
||||
$field_name = 'test';
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'test_field'
|
||||
))->save();
|
||||
$field = FieldConfig::create(array(
|
||||
])->save();
|
||||
$field = FieldConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $this->contentType,
|
||||
));
|
||||
]);
|
||||
$field->save();
|
||||
|
||||
entity_get_form_display('node', $this->contentType, 'default')
|
||||
|
|
@ -429,23 +429,23 @@ class ManageFieldsTest extends WebTestBase {
|
|||
$this->assertFieldById($element_id, '', 'The default value widget was empty.');
|
||||
|
||||
// Check that invalid default values are rejected.
|
||||
$edit = array($element_name => '-1');
|
||||
$edit = [$element_name => '-1'];
|
||||
$this->drupalPostForm($admin_path, $edit, t('Save settings'));
|
||||
$this->assertText("$field_name does not accept the value -1", 'Form validation failed.');
|
||||
|
||||
// Check that the default value is saved.
|
||||
$edit = array($element_name => '1');
|
||||
$edit = [$element_name => '1'];
|
||||
$this->drupalPostForm($admin_path, $edit, t('Save settings'));
|
||||
$this->assertText("Saved $field_name configuration", 'The form was successfully submitted.');
|
||||
$field = FieldConfig::loadByName('node', $this->contentType, $field_name);
|
||||
$this->assertEqual($field->getDefaultValueLiteral(), array(array('value' => 1)), 'The default value was correctly saved.');
|
||||
$this->assertEqual($field->getDefaultValueLiteral(), [['value' => 1]], 'The default value was correctly saved.');
|
||||
|
||||
// Check that the default value shows up in the form
|
||||
$this->drupalGet($admin_path);
|
||||
$this->assertFieldById($element_id, '1', 'The default value widget was displayed with the correct value.');
|
||||
|
||||
// Check that the default value can be emptied.
|
||||
$edit = array($element_name => '');
|
||||
$edit = [$element_name => ''];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save settings'));
|
||||
$this->assertText("Saved $field_name configuration", 'The form was successfully submitted.');
|
||||
$field = FieldConfig::loadByName('node', $this->contentType, $field_name);
|
||||
|
|
@ -458,13 +458,13 @@ class ManageFieldsTest extends WebTestBase {
|
|||
$field_storage->save();
|
||||
|
||||
$this->drupalGet($admin_path);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'required' => 1,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save settings'));
|
||||
|
||||
$this->drupalGet($admin_path);
|
||||
$this->drupalPostForm(NULL, array(), t('Save settings'));
|
||||
$this->drupalPostForm(NULL, [], t('Save settings'));
|
||||
$this->assertText("Saved $field_name configuration", 'The form was successfully submitted.');
|
||||
$field = FieldConfig::loadByName('node', $this->contentType, $field_name);
|
||||
$this->assertEqual($field->getDefaultValueLiteral(), NULL, 'The default value was correctly saved.');
|
||||
|
|
@ -479,14 +479,14 @@ class ManageFieldsTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that deletion removes field storages and fields as expected.
|
||||
*/
|
||||
function testDeleteField() {
|
||||
public function testDeleteField() {
|
||||
// Create a new field.
|
||||
$bundle_path1 = 'admin/structure/types/manage/' . $this->contentType;
|
||||
$this->fieldUIAddNewField($bundle_path1, $this->fieldNameInput, $this->fieldLabel);
|
||||
|
||||
// Create an additional node type.
|
||||
$type_name2 = strtolower($this->randomMachineName(8)) . '_test';
|
||||
$type2 = $this->drupalCreateContentType(array('name' => $type_name2, 'type' => $type_name2));
|
||||
$type2 = $this->drupalCreateContentType(['name' => $type_name2, 'type' => $type_name2]);
|
||||
$type_name2 = $type2->id();
|
||||
|
||||
// Add a field to the second node type.
|
||||
|
|
@ -513,15 +513,15 @@ class ManageFieldsTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that Field UI respects disallowed field names.
|
||||
*/
|
||||
function testDisallowedFieldNames() {
|
||||
public function testDisallowedFieldNames() {
|
||||
// Reset the field prefix so we can test properly.
|
||||
$this->config('field_ui.settings')->set('field_prefix', '')->save();
|
||||
|
||||
$label = 'Disallowed field';
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'label' => $label,
|
||||
'new_storage_type' => 'test_field',
|
||||
);
|
||||
];
|
||||
|
||||
// Try with an entity key.
|
||||
$edit['field_name'] = 'title';
|
||||
|
|
@ -539,35 +539,35 @@ class ManageFieldsTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that Field UI respects locked fields.
|
||||
*/
|
||||
function testLockedField() {
|
||||
public function testLockedField() {
|
||||
// Create a locked field and attach it to a bundle. We need to do this
|
||||
// programmatically as there's no way to create a locked field through UI.
|
||||
$field_name = strtolower($this->randomMachineName(8));
|
||||
$field_storage = FieldStorageConfig::create(array(
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'test_field',
|
||||
'cardinality' => 1,
|
||||
'locked' => TRUE
|
||||
));
|
||||
]);
|
||||
$field_storage->save();
|
||||
FieldConfig::create(array(
|
||||
FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
'bundle' => $this->contentType,
|
||||
))->save();
|
||||
])->save();
|
||||
entity_get_form_display('node', $this->contentType, 'default')
|
||||
->setComponent($field_name, array(
|
||||
->setComponent($field_name, [
|
||||
'type' => 'test_field_widget',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
|
||||
// Check that the links for edit and delete are not present.
|
||||
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields');
|
||||
$locked = $this->xpath('//tr[@id=:field_name]/td[4]', array(':field_name' => $field_name));
|
||||
$locked = $this->xpath('//tr[@id=:field_name]/td[4]', [':field_name' => $field_name]);
|
||||
$this->assertTrue(in_array('Locked', $locked), 'Field is marked as Locked in the UI');
|
||||
$edit_link = $this->xpath('//tr[@id=:field_name]/td[4]', array(':field_name' => $field_name));
|
||||
$edit_link = $this->xpath('//tr[@id=:field_name]/td[4]', [':field_name' => $field_name]);
|
||||
$this->assertFalse(in_array('edit', $edit_link), 'Edit option for locked field is not present the UI');
|
||||
$delete_link = $this->xpath('//tr[@id=:field_name]/td[4]', array(':field_name' => $field_name));
|
||||
$delete_link = $this->xpath('//tr[@id=:field_name]/td[4]', [':field_name' => $field_name]);
|
||||
$this->assertFalse(in_array('delete', $delete_link), 'Delete option for locked field is not present the UI');
|
||||
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/node.' . $this->contentType . '.' . $field_name . '/delete');
|
||||
$this->assertResponse(403);
|
||||
|
|
@ -576,7 +576,7 @@ class ManageFieldsTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that Field UI respects the 'no_ui' flag in the field type definition.
|
||||
*/
|
||||
function testHiddenFields() {
|
||||
public function testHiddenFields() {
|
||||
// Check that the field type is not available in the 'add new field' row.
|
||||
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/add-field');
|
||||
$this->assertFalse($this->xpath('//select[@id="edit-new-storage-type"]//option[@value="hidden_test_field"]'), "The 'add new field' select respects field types 'no_ui' property.");
|
||||
|
|
@ -584,22 +584,22 @@ class ManageFieldsTest extends WebTestBase {
|
|||
|
||||
// Create a field storage and a field programmatically.
|
||||
$field_name = 'hidden_test_field';
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'node',
|
||||
'type' => $field_name,
|
||||
))->save();
|
||||
$field = array(
|
||||
])->save();
|
||||
$field = [
|
||||
'field_name' => $field_name,
|
||||
'bundle' => $this->contentType,
|
||||
'entity_type' => 'node',
|
||||
'label' => t('Hidden field'),
|
||||
);
|
||||
];
|
||||
FieldConfig::create($field)->save();
|
||||
entity_get_form_display('node', $this->contentType, 'default')
|
||||
->setComponent($field_name)
|
||||
->save();
|
||||
$this->assertTrue(FieldConfig::load('node.' . $this->contentType . '.' . $field_name), format_string('A field of the field storage %field was created programmatically.', array('%field' => $field_name)));
|
||||
$this->assertTrue(FieldConfig::load('node.' . $this->contentType . '.' . $field_name), format_string('A field of the field storage %field was created programmatically.', ['%field' => $field_name]));
|
||||
|
||||
// Check that the newly added field appears on the 'Manage Fields'
|
||||
// screen.
|
||||
|
|
@ -609,17 +609,17 @@ class ManageFieldsTest extends WebTestBase {
|
|||
// Check that the field does not appear in the 're-use existing field' row
|
||||
// on other bundles.
|
||||
$this->drupalGet('admin/structure/types/manage/page/fields/add-field');
|
||||
$this->assertFalse($this->xpath('//select[@id="edit-existing-storage-name"]//option[@value=:field_name]', array(':field_name' => $field_name)), "The 're-use existing field' select respects field types 'no_ui' property.");
|
||||
$this->assertTrue($this->xpath('//select[@id="edit-existing-storage-name"]//option[@value=:field_name]', array(':field_name' => 'field_tags')), "The 're-use existing field' select shows a valid option.");
|
||||
$this->assertFalse($this->xpath('//select[@id="edit-existing-storage-name"]//option[@value=:field_name]', [':field_name' => $field_name]), "The 're-use existing field' select respects field types 'no_ui' property.");
|
||||
$this->assertTrue($this->xpath('//select[@id="edit-existing-storage-name"]//option[@value=:field_name]', [':field_name' => 'field_tags']), "The 're-use existing field' select shows a valid option.");
|
||||
|
||||
// Check that non-configurable fields are not available.
|
||||
$field_types = \Drupal::service('plugin.manager.field.field_type')->getDefinitions();
|
||||
foreach ($field_types as $field_type => $definition) {
|
||||
if (empty($definition['no_ui'])) {
|
||||
$this->assertTrue($this->xpath('//select[@id="edit-new-storage-type"]//option[@value=:field_type]', array(':field_type' => $field_type)), SafeMarkup::format('Configurable field type @field_type is available.', array('@field_type' => $field_type)));
|
||||
$this->assertTrue($this->xpath('//select[@id="edit-new-storage-type"]//option[@value=:field_type]', [':field_type' => $field_type]), SafeMarkup::format('Configurable field type @field_type is available.', ['@field_type' => $field_type]));
|
||||
}
|
||||
else {
|
||||
$this->assertFalse($this->xpath('//select[@id="edit-new-storage-type"]//option[@value=:field_type]', array(':field_type' => $field_type)), SafeMarkup::format('Non-configurable field type @field_type is not available.', array('@field_type' => $field_type)));
|
||||
$this->assertFalse($this->xpath('//select[@id="edit-new-storage-type"]//option[@value=:field_type]', [':field_type' => $field_type]), SafeMarkup::format('Non-configurable field type @field_type is not available.', ['@field_type' => $field_type]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -627,19 +627,19 @@ class ManageFieldsTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that a duplicate field name is caught by validation.
|
||||
*/
|
||||
function testDuplicateFieldName() {
|
||||
public function testDuplicateFieldName() {
|
||||
// field_tags already exists, so we're expecting an error when trying to
|
||||
// create a new field with the same name.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'field_name' => 'tags',
|
||||
'label' => $this->randomMachineName(),
|
||||
'new_storage_type' => 'entity_reference',
|
||||
);
|
||||
];
|
||||
$url = 'admin/structure/types/manage/' . $this->contentType . '/fields/add-field';
|
||||
$this->drupalPostForm($url, $edit, t('Save and continue'));
|
||||
|
||||
$this->assertText(t('The machine-readable name is already in use. It must be unique.'));
|
||||
$this->assertUrl($url, array(), 'Stayed on the same page.');
|
||||
$this->assertUrl($url, [], 'Stayed on the same page.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -659,7 +659,7 @@ class ManageFieldsTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that deletion removes field storages and fields as expected for a term.
|
||||
*/
|
||||
function testDeleteTaxonomyField() {
|
||||
public function testDeleteTaxonomyField() {
|
||||
// Create a new field.
|
||||
$bundle_path = 'admin/structure/taxonomy/manage/tags/overview';
|
||||
|
||||
|
|
@ -677,26 +677,26 @@ class ManageFieldsTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that help descriptions render valid HTML.
|
||||
*/
|
||||
function testHelpDescriptions() {
|
||||
public function testHelpDescriptions() {
|
||||
// Create an image field
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => 'field_image',
|
||||
'entity_type' => 'node',
|
||||
'type' => 'image',
|
||||
))->save();
|
||||
])->save();
|
||||
|
||||
FieldConfig::create(array(
|
||||
FieldConfig::create([
|
||||
'field_name' => 'field_image',
|
||||
'entity_type' => 'node',
|
||||
'label' => 'Image',
|
||||
'bundle' => 'article',
|
||||
))->save();
|
||||
])->save();
|
||||
|
||||
entity_get_form_display('node', 'article', 'default')->setComponent('field_image')->save();
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'description' => '<strong>Test with an upload field.',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_image', $edit, t('Save settings'));
|
||||
|
||||
// Check that hook_field_widget_form_alter() does believe this is the
|
||||
|
|
@ -704,9 +704,9 @@ class ManageFieldsTest extends WebTestBase {
|
|||
$this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_tags');
|
||||
$this->assertText('From hook_field_widget_form_alter(): Default form is true.', 'Default value form in hook_field_widget_form_alter().');
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'description' => '<em>Test with a non upload field.',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_tags', $edit, t('Save settings'));
|
||||
|
||||
$this->drupalGet('node/add/article');
|
||||
|
|
@ -717,7 +717,7 @@ class ManageFieldsTest extends WebTestBase {
|
|||
/**
|
||||
* Tests that the field list administration page operates correctly.
|
||||
*/
|
||||
function fieldListAdminPage() {
|
||||
public function fieldListAdminPage() {
|
||||
$this->drupalGet('admin/reports/fields');
|
||||
$this->assertText($this->fieldName, 'Field name is displayed in field list.');
|
||||
$this->assertTrue($this->assertLinkByHref('admin/structure/types/manage/' . $this->contentType . '/fields'), 'Link to content type using field is displayed in field list.');
|
||||
|
|
|
|||
Reference in a new issue