updated core and modules

This commit is contained in:
Bachir Soussi Chiadmi
2017-09-09 16:27:51 +02:00
parent 027aa99b32
commit 41863f872c
7810 changed files with 318922 additions and 83631 deletions
@@ -24,20 +24,20 @@ class TelephoneLinkFormatter extends FormatterBase {
* {@inheritdoc}
*/
public static function defaultSettings() {
return array(
return [
'title' => '',
) + parent::defaultSettings();
] + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements['title'] = array(
$elements['title'] = [
'#type' => 'textfield',
'#title' => t('Title to replace basic numeric telephone number display'),
'#default_value' => $this->getSetting('title'),
);
];
return $elements;
}
@@ -46,11 +46,11 @@ class TelephoneLinkFormatter extends FormatterBase {
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$summary = [];
$settings = $this->getSettings();
if (!empty($settings['title'])) {
$summary[] = t('Link using text: @title', array('@title' => $settings['title']));
$summary[] = t('Link using text: @title', ['@title' => $settings['title']]);
}
else {
$summary[] = t('Link using provided telephone number.');
@@ -63,23 +63,23 @@ class TelephoneLinkFormatter extends FormatterBase {
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$element = array();
$element = [];
$title_setting = $this->getSetting('title');
foreach ($items as $delta => $item) {
// Render each element as link.
$element[$delta] = array(
$element[$delta] = [
'#type' => 'link',
// Use custom title if available, otherwise use the telephone number
// itself as title.
'#title' => $title_setting ?: $item->value,
// Prepend 'tel:' to the telephone number.
'#url' => Url::fromUri('tel:' . rawurlencode(preg_replace('/\s+/', '', $item->value))),
'#options' => array('external' => TRUE),
);
'#options' => ['external' => TRUE],
];
if (!empty($item->_attributes)) {
$element[$delta]['#options'] += array('attributes' => array());
$element[$delta]['#options'] += ['attributes' => []];
$element[$delta]['#options']['attributes'] += $item->_attributes;
// Unset field item attributes since they have been included in the
// formatter output and should not be rendered in the field template.
@@ -25,14 +25,14 @@ class TelephoneItem extends FieldItemBase {
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return array(
'columns' => array(
'value' => array(
return [
'columns' => [
'value' => [
'type' => 'varchar',
'length' => 256,
),
),
);
],
],
];
}
/**
@@ -62,14 +62,14 @@ class TelephoneItem extends FieldItemBase {
$constraints = parent::getConstraints();
$max_length = 256;
$constraints[] = $constraint_manager->create('ComplexData', array(
'value' => array(
'Length' => array(
$constraints[] = $constraint_manager->create('ComplexData', [
'value' => [
'Length' => [
'max' => $max_length,
'maxMessage' => t('%name: the telephone number may not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length)),
)
),
));
'maxMessage' => t('%name: the telephone number may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length]),
]
],
]);
return $constraints;
}
@@ -23,21 +23,21 @@ class TelephoneDefaultWidget extends WidgetBase {
* {@inheritdoc}
*/
public static function defaultSettings() {
return array(
return [
'placeholder' => '',
) + parent::defaultSettings();
] + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['placeholder'] = array(
$element['placeholder'] = [
'#type' => 'textfield',
'#title' => t('Placeholder'),
'#default_value' => $this->getSetting('placeholder'),
'#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'),
);
];
return $element;
}
@@ -45,11 +45,11 @@ class TelephoneDefaultWidget extends WidgetBase {
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$summary = [];
$placeholder = $this->getSetting('placeholder');
if (!empty($placeholder)) {
$summary[] = t('Placeholder: @placeholder', array('@placeholder' => $placeholder));
$summary[] = t('Placeholder: @placeholder', ['@placeholder' => $placeholder]);
}
else {
$summary[] = t('No placeholder');
@@ -62,11 +62,11 @@ class TelephoneDefaultWidget extends WidgetBase {
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element['value'] = $element + array(
$element['value'] = $element + [
'#type' => 'tel',
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL,
'#placeholder' => $this->getSetting('placeholder'),
);
];
return $element;
}
+3 -3
View File
@@ -7,8 +7,8 @@ package: Field types
dependencies:
- field
# Information added by Drupal.org packaging script on 2016-08-03
version: '8.1.8'
# Information added by Drupal.org packaging script on 2017-08-16
version: '8.3.7'
core: '8.x'
project: 'drupal'
datestamp: 1470233790
datestamp: 1502903957
+2 -2
View File
@@ -15,11 +15,11 @@ function telephone_help($route_name, RouteMatchInterface $route_match) {
case 'help.page.telephone':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Telephone module allows you to create fields that contain telephone numbers. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":telephone_documentation">online documentation for the Telephone module</a>.', array(':field' => \Drupal::url('help.page', array('name' => 'field')), ':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', array('name' => 'field_ui')) : '#', ':telephone_documentation' => 'https://www.drupal.org/documentation/modules/telephone')) . '</p>';
$output .= '<p>' . t('The Telephone module allows you to create fields that contain telephone numbers. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":telephone_documentation">online documentation for the Telephone module</a>.', [':field' => \Drupal::url('help.page', ['name' => 'field']), ':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#', ':telephone_documentation' => 'https://www.drupal.org/documentation/modules/telephone']) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Managing and displaying telephone fields') . '</dt>';
$output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the telephone field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', array(':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', array('name' => 'field_ui')) : '#')) . '</dd>';
$output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the telephone field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#']) . '</dd>';
$output .= '<dt>' . t('Displaying telephone numbers as links') . '</dt>';
$output .= '<dd>' . t('Telephone numbers can be displayed as links with the scheme name <em>tel:</em> by choosing the <em>Telephone</em> display format on the <em>Manage display</em> page. Any spaces will be stripped out of the link text. This semantic markup improves the user experience on mobile and assistive technology devices.') . '</dd>';
$output .= '</dl>';
@@ -0,0 +1,102 @@
<?php
namespace Drupal\Tests\telephone\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\BrowserTestBase;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests the creation of telephone fields.
*
* @group telephone
*/
class TelephoneFieldTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'field',
'node',
'telephone'
];
/**
* A user with permission to create articles.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
protected function setUp() {
parent::setUp();
$this->drupalCreateContentType(['type' => 'article']);
$this->webUser = $this->drupalCreateUser(['create article content', 'edit own article content']);
$this->drupalLogin($this->webUser);
}
// Test fields.
/**
* Helper function for testTelephoneField().
*/
public function testTelephoneField() {
// Add the telephone field to the article content type.
FieldStorageConfig::create([
'field_name' => 'field_telephone',
'entity_type' => 'node',
'type' => 'telephone',
])->save();
FieldConfig::create([
'field_name' => 'field_telephone',
'label' => 'Telephone Number',
'entity_type' => 'node',
'bundle' => 'article',
])->save();
entity_get_form_display('node', 'article', 'default')
->setComponent('field_telephone', [
'type' => 'telephone_default',
'settings' => [
'placeholder' => '123-456-7890',
],
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent('field_telephone', [
'type' => 'telephone_link',
'weight' => 1,
])
->save();
// Display creation form.
$this->drupalGet('node/add/article');
$this->assertFieldByName("field_telephone[0][value]", '', 'Widget found.');
$this->assertRaw('placeholder="123-456-7890"');
// Test basic entry of telephone field.
$edit = [
'title[0][value]' => $this->randomMachineName(),
'field_telephone[0][value]' => "123456789",
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw('<a href="tel:123456789">', 'A telephone link is provided on the article node page.');
// Add number with a space in it. Need to ensure it is stripped on output.
$edit = [
'title[0][value]' => $this->randomMachineName(),
'field_telephone[0][value]' => "1234 56789",
];
$this->drupalPostForm('node/add/article', $edit, t('Save'));
$this->assertRaw('<a href="tel:123456789">', 'Telephone link is output with whitespace removed.');
}
}
@@ -21,17 +21,17 @@ class TelephoneItemTest extends FieldKernelTestBase {
*
* @var array
*/
public static $modules = array('telephone');
public static $modules = ['telephone'];
protected function setUp() {
parent::setUp();
// Create a telephone field storage and field for validation.
FieldStorageConfig::create(array(
FieldStorageConfig::create([
'field_name' => 'field_test',
'entity_type' => 'entity_test',
'type' => 'telephone',
))->save();
])->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test',
@@ -52,7 +52,7 @@ class TelephoneItemTest extends FieldKernelTestBase {
// Verify entity has been created properly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertTrue($entity->field_test instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->field_test[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->field_test->value, $value);
@@ -65,7 +65,7 @@ class TelephoneItemTest extends FieldKernelTestBase {
// Read changed entity and assert changed values.
$entity->save();
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertEqual($entity->field_test->value, $new_value);
// Test sample item generation.