updated core from 8.4 to 8.5 : bug with login_destination

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-13 14:01:21 +01:00
parent 0d78da249b
commit e668535a4e
3486 changed files with 89604 additions and 33283 deletions
+3 -3
View File
@@ -7,8 +7,8 @@ package: Field types
dependencies:
- field
# Information added by Drupal.org packaging script on 2018-01-03
version: '8.4.4'
# Information added by Drupal.org packaging script on 2018-03-07
version: '8.5.0'
core: '8.x'
project: 'drupal'
datestamp: 1515021228
datestamp: 1520457825
@@ -151,10 +151,9 @@ class LinkWidget extends WidgetBase {
*/
public static function validateTitleElement(&$element, FormStateInterface $form_state, $form) {
if ($element['uri']['#value'] !== '' && $element['title']['#value'] === '') {
$element['title']['#required'] = TRUE;
// We expect the field name placeholder value to be wrapped in t() here,
// so it won't be escaped again as it's already marked safe.
$form_state->setError($element['title'], t('@name field is required.', ['@name' => $element['title']['#title']]));
$form_state->setError($element['title'], t('@title field is required if there is @uri input.', ['@title' => $element['title']['#title'], '@uri' => $element['uri']['#title']]));
}
}
@@ -218,12 +217,29 @@ class LinkWidget extends WidgetBase {
'#default_value' => isset($items[$delta]->title) ? $items[$delta]->title : NULL,
'#maxlength' => 255,
'#access' => $this->getFieldSetting('title') != DRUPAL_DISABLED,
'#required' => $this->getFieldSetting('title') === DRUPAL_REQUIRED && $element['#required'],
];
// Post-process the title field to make it conditionally required if URL is
// non-empty. Omit the validation on the field edit form, since the field
// settings cannot be saved otherwise.
if (!$this->isDefaultValueWidget($form_state) && $this->getFieldSetting('title') == DRUPAL_REQUIRED) {
if (!$this->isDefaultValueWidget($form_state) && $this->getFieldSetting('title') === DRUPAL_REQUIRED) {
$element['#element_validate'][] = [get_called_class(), 'validateTitleElement'];
if (!$element['title']['#required']) {
// Make title required on the front-end when URI filled-in.
$field_name = $this->fieldDefinition->getName();
$parents = $element['#field_parents'];
$parents[] = $field_name;
$selector = $root = array_shift($parents);
if ($parents) {
$selector = $root . '[' . implode('][', $parents) . ']';
}
$element['title']['#states']['required'] = [
':input[name="' . $selector . '[' . $delta . '][uri]"]' => ['filled' => TRUE]
];
}
}
// Exposing the attributes array in the widget is left for alternate and more
@@ -241,6 +257,29 @@ class LinkWidget extends WidgetBase {
// title of the 'uri' element.
if ($this->getFieldSetting('title') == DRUPAL_DISABLED) {
$element['uri']['#title'] = $element['#title'];
// By default the field description is added to the title field. Since
// the title field is disabled, we add the description, if given, to the
// uri element instead.
if (!empty($element['#description'])) {
if (empty($element['uri']['#description'])) {
$element['uri']['#description'] = $element['#description'];
}
else {
// If we have the description of the type of field together with
// the user provided description, we want to make a distinction
// between "core help text" and "user entered help text". To make
// this distinction more clear, we put them in an unordered list.
$element['uri']['#description'] = [
'#theme' => 'item_list',
'#items' => [
// Assume the user-specified description has the most relevance,
// so place it first.
$element['#description'],
$element['uri']['#description'],
],
];
}
}
}
// Otherwise wrap everything in a details element.
else {
@@ -13,7 +13,9 @@ use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
* core = {6},
* type_map = {
* "link_field" = "link"
* }
* },
* source_module = "link",
* destination_module = "link"
* )
*
* @deprecated in Drupal 8.3.x and will be removed in Drupal 9.0.x. Use
@@ -13,7 +13,9 @@ use Drupal\migrate\Plugin\MigrationInterface;
* core = {7},
* type_map = {
* "link_field" = "link"
* }
* },
* source_module = "link",
* destination_module = "link"
* )
*
* This plugin provides the exact same functionality as the Drupal 6 "link"
@@ -11,7 +11,9 @@ use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
* core = {6},
* type_map = {
* "link_field" = "link"
* }
* },
* source_module = "link",
* destination_module = "link"
* )
*/
class LinkField extends FieldPluginBase {
@@ -11,7 +11,9 @@ use Drupal\migrate\Plugin\MigrationInterface;
* core = {7},
* type_map = {
* "link_field" = "link"
* }
* },
* source_module = "link",
* destination_module = "link"
* )
*
* This plugin provides the exact same functionality as the Drupal 6 "link"
@@ -20,6 +22,15 @@ use Drupal\migrate\Plugin\MigrationInterface;
*/
class LinkField extends D6LinkField {
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return [
'link_default' => 'link',
];
}
/**
* {@inheritdoc}
*/
@@ -38,8 +38,8 @@ class LinkViewsTokensTest extends ViewTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
ViewTestData::createTestViews(get_class($this), ['link_test_views']);
// Create Basic page node type.
@@ -0,0 +1,14 @@
name: Link test base field
description: Tests link field as an optional base field
type: module
# core: 8.x
hidden: true
dependencies:
- link
- entity_test
# Information added by Drupal.org packaging script on 2018-03-07
version: '8.5.0'
core: '8.x'
project: 'drupal'
datestamp: 1520457825
@@ -0,0 +1,35 @@
<?php
/**
* @file
* Contains main module functions.
*/
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\link\LinkItemInterface;
/**
* Implements hook_entity_base_field_info().
*/
function link_test_base_field_entity_base_field_info(EntityTypeInterface $entity_type) {
$fields = [];
if ($entity_type->id() === 'entity_test') {
$fields['links'] = BaseFieldDefinition::create('link')
->setLabel(t('Links'))
->setRevisionable(TRUE)
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDescription(t('Add links to the entity.'))
->setRequired(FALSE)
->setSettings([
'link_type' => LinkItemInterface::LINK_GENERIC,
'title' => DRUPAL_REQUIRED,
])
->setDisplayOptions('form', [
'type' => 'link_default',
'weight' => 49,
]);
}
return $fields;
}
@@ -9,8 +9,8 @@ dependencies:
- views
- link
# Information added by Drupal.org packaging script on 2018-01-03
version: '8.4.4'
# Information added by Drupal.org packaging script on 2018-03-07
version: '8.5.0'
core: '8.x'
project: 'drupal'
datestamp: 1515021228
datestamp: 1520457825
@@ -24,7 +24,12 @@ class LinkFieldTest extends BrowserTestBase {
*
* @var array
*/
public static $modules = ['entity_test', 'link', 'node'];
public static $modules = [
'entity_test',
'link',
'node',
'link_test_base_field',
];
/**
* A field to use in this test class.
@@ -282,7 +287,7 @@ class LinkFieldTest extends BrowserTestBase {
"{$field_name}[0][uri]" => 'http://www.example.com',
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('@name field is required.', ['@name' => t('Link text')]));
$this->assertText(t('@title field is required if there is @uri input.', ['@title' => t('Link text'), '@uri' => t('URL')]));
// Verify that the link text is not required, if the URL is empty.
$edit = [
@@ -2,7 +2,10 @@
namespace Drupal\Tests\link\Functional;
use Drupal\Component\Utility\Unicode;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\link\LinkItemInterface;
use Drupal\Tests\BrowserTestBase;
@@ -30,14 +33,37 @@ class LinkFieldUITest extends BrowserTestBase {
*/
protected $adminUser;
/**
* A user that should see the help texts.
*
* @var \Drupal\user\Entity\User
*/
protected $helpTextUser;
/**
* The first content type to add fields to.
*
* @var \Drupal\node\Entity\NodeType
*/
protected $firstContentType;
/**
* The second content type to add fields to.
*
* @var \Drupal\node\Entity\NodeType
*/
protected $secondContentType;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->firstContentType = $this->drupalCreateContentType();
$this->secondContentType = $this->drupalCreateContentType();
$this->adminUser = $this->drupalCreateUser(['administer content types', 'administer node fields', 'administer node display']);
$this->drupalLogin($this->adminUser);
$this->helpTextUser = $this->drupalCreateUser(['create ' . $this->secondContentType->id() . ' content']);
$this->drupalPlaceBlock('system_breadcrumb_block');
}
@@ -45,16 +71,91 @@ class LinkFieldUITest extends BrowserTestBase {
* Tests the link field UI.
*/
public function testFieldUI() {
// Add a content type.
$type = $this->drupalCreateContentType();
$type_path = 'admin/structure/types/manage/' . $type->id();
$add_path = 'node/add/' . $type->id();
foreach ($this->providerTestFieldUI() as $item) {
list($cardinality, $link_type, $title, $label, $field_name) = $item;
$this->runFieldUIItem($cardinality, $link_type, $title, $label, $field_name);
}
}
/**
* Provides test data for ::testFieldUI().
*/
protected function providerTestFieldUI() {
// There are many combinations of field settings: where the description
// should show: variation on internal, external, both; cardinality (where
// the fieldset is hidden or used); and link text shown (required or
// optional) or disabled. There are two descriptions: field and URL help
// text.
$cardinalities = [1, 2];
$title_settings = [
DRUPAL_DISABLED,
DRUPAL_OPTIONAL,
];
$link_types = [
LinkItemInterface::LINK_EXTERNAL,
LinkItemInterface::LINK_GENERIC,
LinkItemInterface::LINK_INTERNAL,
];
// Test all variations of link types on all cardinalities.
foreach ($cardinalities as $cardinality) {
foreach ($link_types as $link_type) {
// Now, test this with both the title enabled and disabled.
foreach ($title_settings as $title_setting) {
// Test both empty and non-empty labels.
foreach ([TRUE, FALSE] as $label_provided) {
// Generate a unique machine name for the field so it can be
// identified in the test.
$id = implode('_', [
'link',
$cardinality,
$link_type,
$title_setting,
(int) $label_provided,
]);
// Use a unique label that contains some HTML.
$label = '<img src="http://example.com">' . $id;
yield [
$cardinality,
$link_type,
$title_setting,
$label_provided ? $label : '',
$id,
];
}
}
}
}
}
/**
* Tests one link field UI item.
*
* @param int $cardinality
* The field cardinality.
* @param int $link_type
* Determine if the link is external, internal or both.
* @param int $title
* Determine if the field will display the link text field.
* @param string $label
* The field label.
* @param string $field_name
* The unique machine name for the field.
*/
public function runFieldUIItem($cardinality, $link_type, $title, $label, $field_name) {
$this->drupalLogin($this->adminUser);
$type_path = 'admin/structure/types/manage/' . $this->firstContentType->id();
// Add a link field to the newly-created type. It defaults to allowing both
// internal and external links.
$label = $this->randomMachineName();
$field_name = Unicode::strtolower($label);
$this->fieldUIAddNewField($type_path, $field_name, $label, 'link');
$field_label = str_replace('_', ' ', $field_name);
$description = 'link field description';
$field_edit = [
'description' => $description,
];
$this->fieldUIAddNewField($type_path, $field_name, $field_label, 'link', [], $field_edit);
// Load the formatter page to check that the settings summary does not
// generate warnings.
@@ -62,31 +163,94 @@ class LinkFieldUITest extends BrowserTestBase {
$this->drupalGet("$type_path/display");
$this->assertText(t('Link text trimmed to @limit characters', ['@limit' => 80]));
// Test the help text displays when the link field allows both internal and
// external links.
$this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content']));
$storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'node',
'type' => 'link',
'cardinality' => $cardinality,
]);
$storage->save();
FieldConfig::create([
'field_storage' => $storage,
'label' => $label,
'bundle' => $this->secondContentType->id(),
'settings' => [
'title' => $title,
'link_type' => $link_type,
],
])->save();
// Make the fields visible in the form display.
$form_display_id = implode('.', ['node', $this->secondContentType->id(), 'default']);
$form_display = EntityFormDisplay::load($form_display_id);
$form_display->setComponent($field_name, ['region' => 'content']);
$form_display->save();
// Log in a user that is allowed to create this content type, see if
// the user can see the expected help text.
$this->drupalLogin($this->helpTextUser);
$add_path = 'node/add/' . $this->secondContentType->id();
$this->drupalGet($add_path);
$this->assertRaw('You can also enter an internal path such as <em class="placeholder">/node/add</em> or an external URL such as <em class="placeholder">http://example.com</em>.');
// Log in an admin to set up the next content type.
$this->drupalLogin($this->adminUser);
$expected_help_texts = [
LinkItemInterface::LINK_EXTERNAL => 'This must be an external URL such as <em class="placeholder">http://example.com</em>.',
LinkItemInterface::LINK_GENERIC => 'You can also enter an internal path such as <em class="placeholder">/node/add</em> or an external URL such as <em class="placeholder">http://example.com</em>. Enter <em class="placeholder">&lt;front&gt;</em> to link to the front page.',
LinkItemInterface::LINK_INTERNAL => rtrim(\Drupal::url('<front>', [], ['absolute' => TRUE]), '/'),
];
// Add a different content type.
$type = $this->drupalCreateContentType();
$type_path = 'admin/structure/types/manage/' . $type->id();
$add_path = 'node/add/' . $type->id();
// Check that the help texts we assume should be there, is there.
$this->assertFieldContainsRawText($field_name, $expected_help_texts[$link_type]);
if ($link_type === LinkItemInterface::LINK_INTERNAL) {
// Internal links have no "system" description. Test that none
// of the other help texts show here.
$this->assertNoFieldContainsRawText($field_name, $expected_help_texts[LinkItemInterface::LINK_EXTERNAL]);
$this->assertNoFieldContainsRawText($field_name, $expected_help_texts[LinkItemInterface::LINK_GENERIC]);
}
// Also assert that the description we made is here, no matter what the
// cardinality or link setting.
if (!empty($label)) {
$this->assertFieldContainsRawText($field_name, $label);
}
}
// Add a link field to the newly-created type. Specify it must allow
// external only links.
$label = $this->randomMachineName();
$field_name = Unicode::strtolower($label);
$field_edit = ['settings[link_type]' => LinkItemInterface::LINK_EXTERNAL];
$this->fieldUIAddNewField($type_path, $field_name, $label, 'link', [], $field_edit);
/**
* Checks that given field contains the given raw text.
*
* @param string $field_name
* The name of the field to check.
* @param string $text
* The text to check.
*/
protected function assertFieldContainsRawText($field_name, $text) {
$this->assertTrue((bool) preg_match('/' . preg_quote($text, '/') . '/ui', $this->getFieldHtml($field_name)));
}
// Test the help text displays when link allows only external links.
$this->drupalLogin($this->drupalCreateUser(['create ' . $type->id() . ' content']));
$this->drupalGet($add_path);
$this->assertRaw('This must be an external URL such as <em class="placeholder">http://example.com</em>.');
/**
* Checks that given field does not contain the given raw text.
*
* @param string $field_name
* The name of the field to check.
* @param string $text
* The text to check.
*/
protected function assertNoFieldContainsRawText($field_name, $text) {
$this->assertFalse((bool) preg_match('/' . preg_quote($text, '/') . '/ui', $this->getFieldHtml($field_name)));
}
/**
* Returns the raw HTML for the given field.
*
* @param $field_name
* The name of the field for which to return the HTML.
*
* @return string
* The raw HTML.
*/
protected function getFieldHtml($field_name) {
$css_id = Html::cleanCssIdentifier('edit-' . $field_name . '-wrapper');
return $this->xpath('//*[@id=:id]', [':id' => $css_id])[0]->getHtml();
}
}
@@ -53,6 +53,8 @@ class LinkCckTest extends KernelTestBase {
/**
* @covers ::processCckFieldValues
* @expectedDeprecation CckFieldPluginBase is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase instead.
* @expectedDeprecation MigrateCckFieldInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.
*/
public function testProcessCckFieldValues() {
$this->plugin->processFieldInstance($this->migration);
@@ -46,6 +46,7 @@ class LinkCckTest extends UnitTestCase {
/**
* @covers ::processCckFieldValues
* @expectedDeprecation LinkField is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\link\Plugin\migrate\field\d6\LinkField instead.
*/
public function testProcessCckFieldValues() {
$this->plugin->processCckFieldValues($this->migration, 'somefieldname', []);