diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php index bd06234..41d7d97 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php @@ -76,17 +76,19 @@ public function getInstance(array $options) { $configuration = $this->prepareConfiguration($field['type'], $configuration); } - $plugin_id = $configuration['type']; + if (isset($configuration['type'])) { + $plugin_id = $configuration['type']; - // Switch back to default formatter if either: - // - $type_info doesn't exist (the widget type is unknown), - // - the field type is not allowed for the widget. - $definition = $this->getDefinition($configuration['type']); - if (!isset($definition['class']) || !in_array($field['type'], $definition['field_types'])) { - // Grab the default widget for the field type. - $field_type_definition = field_info_field_types($field['type']); - if (!empty($field_type_definition['default_formatter'])) { - $plugin_id = $field_type_definition['default_formatter']; + // Switch back to default formatter if either: + // - $type_info doesn't exist (the formatter type is unknown), + // - the field type is not allowed for the formatter. + $definition = $this->getDefinition($configuration['type']); + if (!isset($definition['class']) || !in_array($field['type'], $definition['field_types'])) { + // Grab the default formatter for the field type. + $field_type_definition = field_info_field_types($field['type']); + if (!empty($field_type_definition['default_formatter'])) { + $plugin_id = $field_type_definition['default_formatter']; + } } } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php index d8dea9b..c579a24 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php @@ -153,7 +153,7 @@ public function build(array $form, array &$form_state) { '#title' => t('Formatter for @title', array('@title' => $instance['label'])), '#title_display' => 'invisible', '#options' => $formatter_options, - '#default_value' => $display_options ? $display_options['type'] : 'hidden', + '#default_value' => isset($display_options['type']) ? $display_options['type'] : 'hidden', '#parents' => array('fields', $name, 'type'), '#attributes' => array('class' => array('field-formatter-type')), ), @@ -170,7 +170,7 @@ public function build(array $form, array &$form_state) { } // Get the corresponding formatter object. - if ($display_options && $display_options['type'] != 'hidden') { + if (isset($display_options['type']) && $display_options['type'] != 'hidden') { $formatter = drupal_container()->get('plugin.manager.field.formatter')->getInstance(array( 'instance' => $instance, 'view_mode' => $this->view_mode, diff --git a/core/modules/path/lib/Drupal/path/Plugin/field/widget/PathWidget.php b/core/modules/path/lib/Drupal/path/Plugin/field/widget/PathWidget.php index 712ba46..7460948 100644 --- a/core/modules/path/lib/Drupal/path/Plugin/field/widget/PathWidget.php +++ b/core/modules/path/lib/Drupal/path/Plugin/field/widget/PathWidget.php @@ -66,6 +66,7 @@ public function formElement(array $items, $delta, array $element, $langcode, arr ), '#access' => user_access('create url aliases') || user_access('administer url aliases'), '#tree' => TRUE, + '#path' => $path, '#element_validate' => array(array($this, 'validatePath')), ); $element['pid'] = array( @@ -86,6 +87,10 @@ public function formElement(array $items, $delta, array $element, $langcode, arr '#maxlength' => 255, '#description' => $element['#description'], ); + // Remove the #description from $element, as it would be duplicated into the + // container otherwise. + unset($element['#description']); + $element['source'] = array( '#type' => 'value', '#value' => $path['source'], @@ -99,8 +104,7 @@ public function formElement(array $items, $delta, array $element, $langcode, arr if (isset($form['advanced'])) { $element['#type'] = 'details'; $element['#group'] = 'advanced'; - $element['#title'] = t('URL path settings'); - $element['#collapsed'] = empty($path['pid']) && empty($path['value']); + $element['#title'] = t('URL settings'); } return $element; diff --git a/core/modules/path/lib/Drupal/path/Tests/PathCustomUITest.php b/core/modules/path/lib/Drupal/path/Tests/PathCustomUITest.php new file mode 100644 index 0000000..6013a88 --- /dev/null +++ b/core/modules/path/lib/Drupal/path/Tests/PathCustomUITest.php @@ -0,0 +1,87 @@ + 'Custom URL alias fields', + 'description' => 'Tests custom URL alias fields.', + 'group' => 'Path', + ); + } + + /** + * Tests alias functionality through the admin interfaces. + */ + function testCustomUserAlias() { + $label = 'My URL alias'; + $field_name = 'url_alias'; + $langcode = LANGUAGE_NOT_SPECIFIED; + $edit_field_key = 'field_' . $field_name . '[' . $langcode . '][0][value]'; + + // Add a URL alias field to user accounts. + $this->drupalLogin($this->root_user); + $edit = array( + 'fields[_add_new_field][label]' => $label, + 'fields[_add_new_field][field_name]' => $field_name, + 'fields[_add_new_field][type]' => 'path', + 'fields[_add_new_field][widget_type]' => 'path_default', + ); + $this->drupalPost('admin/config/people/accounts/fields', $edit, t('Save')); + + // Verify that it appears as hidden in the display settings. + $this->drupalGet('admin/config/people/accounts/display'); + $this->assertFieldByName('fields[field_url_alias][type]', 'hidden'); + + // Create a user account and add a URL alias for it. + $account = $this->drupalCreateUser(); + $alias = 'members/foo'; + $edit = array( + $edit_field_key => $alias, + ); + $this->drupalPost("user/$account->uid/edit", $edit, t('Save')); + $this->assertText($label); + + // Verify that the URL alias works. + $this->drupalGet($alias); + $this->assertUrl($alias); + $this->assertResponse(200); + $this->drupalGet("user/$account->uid"); + $this->assertUrl("user/$account->uid"); + $this->assertResponse(200); + + // Remove the URL alias and verify that it was removed. + $edit = array( + $edit_field_key => '', + ); + $this->drupalPost("user/$account->uid/edit", $edit, t('Save')); + $this->drupalGet($alias); + $this->assertUrl($alias); + $this->assertResponse(404); + $this->drupalGet("user/$account->uid"); + $this->assertUrl("user/$account->uid"); + $this->assertResponse(200); + + // Verify that the user is not able to edit the URL alias field. + $this->drupalLogin($account); + $this->drupalGet("user/$account->uid/edit"); + $this->assertNoText($label); + } +} diff --git a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php index 612238e..b9a145b 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php @@ -94,7 +94,7 @@ function testAliasTranslation() { // Translate the node into French. $this->drupalGet('node/' . $node->nid . '/translations'); - $this->clickLink(t('add')); + $this->clickLink(t('Add')); $edit = array(); $edit['title'] = $this->randomName(); $edit['body[fr][0][value]'] = $this->randomName(); diff --git a/core/modules/path/path.module b/core/modules/path/path.module index 73e8362..87f10c1 100644 --- a/core/modules/path/path.module +++ b/core/modules/path/path.module @@ -18,8 +18,10 @@ function path_help($path, $arg) { $output .= '

' . t('The Path module allows you to specify an alias, or custom URL, for any existing internal system path. Aliases should not be confused with URL redirects, which allow you to forward a changed or inactive URL to a new URL. In addition to making URLs more readable, aliases also help search engines index content more effectively. Multiple aliases may be used for a single internal system path. To automate the aliasing of paths, you can install the contributed module Pathauto. For more information, see the online handbook entry for the Path module.', array('@path' => 'http://drupal.org/documentation/modules/path', '@pathauto' => 'http://drupal.org/project/pathauto')) . '

'; $output .= '

' . t('Uses') . '

'; $output .= '
'; + $output .= '
' . t('Enabling aliases') . '
'; + $output .= '
' . t('A URL alias field can be added to content types and other entity bundles that support fields (such as taxonomy vocabularies and user accounts). This field allows users to create or edit a URL alias when they are creating or editing content.') . '
'; $output .= '
' . t('Creating aliases') . '
'; - $output .= '
' . t('Users with sufficient permissions can create aliases under the URL path settings section when they create or edit content. Some examples of aliases are: ', array('@permissions' => url('admin/people/permissions', array('fragment' => 'module-path')))); + $output .= '
' . t('Users with sufficient permissions can create aliases under the URL settings section when they create or edit content. Some examples of aliases are: ', array('@permissions' => url('admin/people/permissions', array('fragment' => 'module-path')))); $output .= '
';