diff -u b/core/lib/Drupal/Core/Field/FormatterPluginManager.php b/core/lib/Drupal/Core/Field/FormatterPluginManager.php --- b/core/lib/Drupal/Core/Field/FormatterPluginManager.php +++ b/core/lib/Drupal/Core/Field/FormatterPluginManager.php @@ -91,6 +91,8 @@ * also be used if the requested formatter is not available. * - settings: (array) Settings specific to the formatter. Each setting * defaults to the default value specified in the formatter definition. + * - third_party_settings: (array) Settings provided by other extensions + * through hook_field_formatter_third_party_settings_form(). * * @return \Drupal\Core\Field\FormatterInterface|null * A formatter object or NULL when plugin is not found. diff -u b/core/lib/Drupal/Core/Field/PluginSettingsBase.php b/core/lib/Drupal/Core/Field/PluginSettingsBase.php --- b/core/lib/Drupal/Core/Field/PluginSettingsBase.php +++ b/core/lib/Drupal/Core/Field/PluginSettingsBase.php @@ -96,11 +96,8 @@ /** * {@inheritdoc} */ - public function getThirdPartySetting($module, $key) { - if (isset($this->thirdPartySettings[$module][$key])) { - return $this->thirdPartySettings[$module][$key]; - } - return NULL; + public function getThirdPartySetting($module, $key, $default = NULL) { + return isset($this->thirdPartySettings[$module][$key]) ? $this->thirdPartySettings[$module][$key] : $default; } /** diff -u b/core/lib/Drupal/Core/Field/PluginSettingsInterface.php b/core/lib/Drupal/Core/Field/PluginSettingsInterface.php --- b/core/lib/Drupal/Core/Field/PluginSettingsInterface.php +++ b/core/lib/Drupal/Core/Field/PluginSettingsInterface.php @@ -65,17 +65,21 @@ public function setSetting($key, $value); /** - * Returns the value of a third-party setting, or its default value if absent. + * Returns the value of a third-party setting, or $default if not set. * * @param string $module * The module providing the third-party setting. * @param string $key * The setting name. + * @param mixed $default + * (optional) The default value if the third party setting is not set. + * Defaults to NULL. * * @return mixed|NULL - * The setting value. Returns NULL if the setting does not exist. + * The setting value. Returns NULL if the setting does not exist and + * $default is not provided. */ - public function getThirdPartySetting($module, $key); + public function getThirdPartySetting($module, $key, $default = NULL); /** * Sets the value of a third-party setting for the plugin. diff -u b/core/lib/Drupal/Core/Field/WidgetPluginManager.php b/core/lib/Drupal/Core/Field/WidgetPluginManager.php --- b/core/lib/Drupal/Core/Field/WidgetPluginManager.php +++ b/core/lib/Drupal/Core/Field/WidgetPluginManager.php @@ -71,6 +71,8 @@ * used if the requested widget is not available. * - settings: (array) Settings specific to the widget. Each setting * defaults to the default value specified in the widget definition. + * - third_party_settings: (array) Settings provided by other extensions + * through hook_field_formatter_third_party_settings_form(). * * @return \Drupal\Core\Field\WidgetInterface|null * A Widget object or NULL when plugin is not found. diff -u b/core/modules/field/tests/modules/field_third_party_test/field_third_party_test.module b/core/modules/field/tests/modules/field_third_party_test/field_third_party_test.module --- b/core/modules/field/tests/modules/field_third_party_test/field_third_party_test.module +++ b/core/modules/field/tests/modules/field_third_party_test/field_third_party_test.module @@ -3,7 +3,7 @@ /** * Implements hook_field_widget_third_party_settings_form(). */ -function field_third_party_test_field_widget_third_party_settings_form($plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $form_mode, $form, $form_state) { +function field_third_party_test_field_widget_third_party_settings_form(\Drupal\Core\Field\WidgetInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $form_mode, $form, $form_state) { $element['field_test_widget_third_party_settings_form'] = array( '#type' => 'textfield', '#title' => t('3rd party widget settings form'), @@ -23,7 +23,7 @@ /** * Implements hook_field_formatter_third_party_settings_form(). */ -function field_third_party_test_field_formatter_third_party_settings_form($plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $view_mode, $form, $form_state) { +function field_third_party_test_field_formatter_third_party_settings_form(\Drupal\Core\Field\FormatterInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $view_mode, $form, $form_state) { $element['field_test_field_formatter_third_party_settings_form'] = array( '#type' => 'textfield', '#title' => t('3rd party formatter settings form'), diff -u b/core/modules/field_ui/field_ui.api.php b/core/modules/field_ui/field_ui.api.php --- b/core/modules/field_ui/field_ui.api.php +++ b/core/modules/field_ui/field_ui.api.php @@ -13,14 +13,14 @@ /** * Allow modules to add settings to field formatters provided by other modules. * - * @param object $plugin - * The field formatter. + * @param \Drupal\Core\Field\FormatterInterface $plugin + * The instantiated field formatter plugin. * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition * The field definition. * @param $view_mode * The entity view mode. * @param array $form - * The The (entire) configuration form array. + * The (entire) configuration form array. * @param array $form_state * The form state. * @@ -29,7 +29,7 @@ * * @see \Drupal\field_ui\DisplayOverView. */ -function hook_field_formatter_third_party_settings_form($plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $view_mode, $form, $form_state) { +function hook_field_formatter_third_party_settings_form(\Drupal\Core\Field\FormatterInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $view_mode, $form, $form_state) { $element = array(); // Add a 'my_setting' checkbox to the settings form for 'foo_formatter' field // formatters. @@ -46,14 +46,14 @@ /** * Allow modules to add settings to field widgets provided by other modules. * - * @param object $plugin - * The field widget. + * @param \Drupal\Core\Field\WidgetInterface $plugin + * The instantiated field widget plugin. * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition * The field definition. * @param $form_mode * The entity form mode. * @param array $form - * The The (entire) configuration form array. + * The (entire) configuration form array. * @param array $form_state * The form state. * @@ -62,7 +62,7 @@ * * @see \Drupal\field_ui\FormDisplayOverView. */ -function hook_field_widget_third_party_settings_form($plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $form_mode, $form, $form_state) { +function hook_field_widget_third_party_settings_form(\Drupal\Core\Field\WidgetInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $form_mode, $form, $form_state) { $element = array(); // Add a 'my_setting' checkbox to the settings form for 'foo_widget' field // widgets. diff -u b/core/modules/field_ui/src/DisplayOverview.php b/core/modules/field_ui/src/DisplayOverview.php --- b/core/modules/field_ui/src/DisplayOverview.php +++ b/core/modules/field_ui/src/DisplayOverview.php @@ -14,6 +14,8 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Field\FieldTypePluginManager; +use Drupal\Core\Field\FormatterInterface; +use Drupal\Core\Field\PluginSettingsInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -230,11 +232,11 @@ /** * {@inheritdoc} */ - protected function alterSettingsForm(array &$settings_form, $plugin, FieldDefinitionInterface $field_definition, array $form, array &$form_state) { - // Iterate through the modules calling their - // field_formatter_third_party_settings_form handlers (if any): + protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition, array $form, array &$form_state) { + $settings_form = array(); + // 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) { - // Index the settings form by module name. $settings_form[$module] = $this->moduleHandler->invoke($module, 'field_formatter_third_party_settings_form', array( $plugin, $field_definition, @@ -243,12 +245,13 @@ $form_state, )); } + return $settings_form; } /** * {@inheritdoc} */ - protected function alterSettingsSummary(array &$summary, $plugin, FieldDefinitionInterface $field_definition) { + protected function alterSettingsSummary(array &$summary, PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition) { $context = array( 'formatter' => $plugin, 'field_definition' => $field_definition, diff -u b/core/modules/field_ui/src/DisplayOverviewBase.php b/core/modules/field_ui/src/DisplayOverviewBase.php --- b/core/modules/field_ui/src/DisplayOverviewBase.php +++ b/core/modules/field_ui/src/DisplayOverviewBase.php @@ -14,6 +14,7 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; +use Drupal\Core\Field\PluginSettingsInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -352,8 +353,7 @@ if ($plugin) { // Generate the settings form and allow other modules to alter it. $settings_form = $plugin->settingsForm($form, $form_state); - $third_party_settings_form = array(); - $this->alterSettingsForm($third_party_settings_form, $plugin, $field_definition, $form, $form_state); + $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); @@ -411,8 +411,7 @@ // Check selected plugin settings to display edit link or not. $settings_form = $plugin->settingsForm($form, $form_state); - $third_party_settings_form = array(); - $this->alterSettingsForm($third_party_settings_form, $plugin, $field_definition, $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( '#type' => 'image_button', @@ -874,30 +873,31 @@ /** - * Alters the widget or formatter settings form. + * Adds the widget or formatter third party settings forms. * - * @param array $settings_form - * The widget or formatter settings form. - * @param object $plugin + * @param \Drupal\Core\Field\PluginSettingsInterface $plugin * The widget or formatter. * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition * The field definition. * @param array $form - * The The (entire) configuration form array. + * The (entire) configuration form array. * @param array $form_state * The form state. + * + * @return array + * The widget or formatter third party settings form. */ - abstract protected function alterSettingsForm(array &$settings_form, $plugin, FieldDefinitionInterface $field_definition, array $form, array &$form_state); + abstract protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition, array $form, array &$form_state); /** * Alters the widget or formatter settings summary. * * @param array $summary * The widget or formatter settings summary. - * @param object $plugin + * @param \Drupal\Core\Field\PluginSettingsInterface $plugin * The widget or formatter. * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition * The field definition. */ - abstract protected function alterSettingsSummary(array &$summary, $plugin, FieldDefinitionInterface $field_definition); + abstract protected function alterSettingsSummary(array &$summary, PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition); } diff -u b/core/modules/field_ui/src/FormDisplayOverview.php b/core/modules/field_ui/src/FormDisplayOverview.php --- b/core/modules/field_ui/src/FormDisplayOverview.php +++ b/core/modules/field_ui/src/FormDisplayOverview.php @@ -14,6 +14,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldTypePluginManager; +use Drupal\Core\Field\PluginSettingsInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -182,11 +183,11 @@ /** * {@inheritdoc} */ - protected function alterSettingsForm(array &$settings_form, $plugin, FieldDefinitionInterface $field_definition, array $form, array &$form_state) { - // Iterate through the modules calling their - // field_widget_third_party_settings_form handlers (if any): + protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition, array $form, array &$form_state) { + $settings_form = array(); + // 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) { - // Index the settings form by module name. $settings_form[$module] = $this->moduleHandler->invoke($module, 'field_widget_third_party_settings_form', array( $plugin, $field_definition, @@ -195,12 +196,13 @@ $form_state, )); } + return $settings_form; } /** * {@inheritdoc} */ - protected function alterSettingsSummary(array &$summary, $plugin, FieldDefinitionInterface $field_definition) { + protected function alterSettingsSummary(array &$summary, PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition) { $context = array( 'widget' => $plugin, 'field_definition' => $field_definition, only in patch2: unchanged: --- a/core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php +++ b/core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php @@ -54,9 +54,8 @@ public function checkConfigSchema(TypedConfigManagerInterface $typed_config, $co } $definition = $typed_config->getDefinition($config_name); $this->schema = $typed_config->create($definition, $config_data); - $errors = array(); foreach ($config_data as $key => $value) { - $errors = array_merge($errors, $this->checkValue($key, $value)); + $errors = $this->checkValue($key, $value); } if (empty($errors)) { return TRUE; only in patch2: unchanged: --- a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php +++ b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php @@ -91,6 +91,8 @@ public function isDisplayConfigurable($display_context); * for the field type will be used. * - settings: (array) Settings for the plugin specified above. The default * settings for the plugin will be used for settings left unspecified. + * - third_party_settings: (array) Settings provided by other extensions + * through hook_field_formatter_third_party_settings_form(). * - weight: (float) The weight of the element. Not needed if 'type' is * 'hidden'. * The defaults of the various display options above get applied by the used