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 55d0e3f..de1b4f5 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 @@ -45,18 +45,21 @@ public function __construct() { */ public function getInstance(array $options) { $instance = $options['instance']; - $type = $options['type']; + $plugin_id = $options['type']; - $definition = $this->getDefinition($type); + $definition = $this->getDefinition($plugin_id); $field = field_info_field($instance['field_name']); // 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. - if (!isset($definition['class']) || !in_array($field['type'], $definition['field_types'])) { + // - the plugin_id is unknown, + // - the field type is not allowed for the formatter. + if (!$definition || !in_array($field['type'], $definition['field_types'])) { // Grab the default widget for the field type. $field_type_definition = field_info_field_types($field['type']); - $type = $field_type_definition['default_formatter']; + if (empty($field_type_definition['default_formatter'])) { + throw new \RuntimeException(t('No valid formatter could be found for field type @type.', array('@type' => $field['type']))); + } + $plugin_id = $field_type_definition['default_formatter']; } $configuration = array( @@ -66,7 +69,7 @@ public function getInstance(array $options) { 'label' => $options['label'], 'view_mode' => $options['view_mode'], ); - return $this->createInstance($type, $configuration); + return $this->createInstance($plugin_id, $configuration); } } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php index 5722807..4fb9664 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php @@ -47,18 +47,21 @@ public function __construct() { */ public function getInstance(array $options) { $instance = $options['instance']; - $type = $options['type']; + $plugin_id = $options['type']; - $definition = $this->getDefinition($type); + $definition = $this->getDefinition($plugin_id); $field = field_info_field($instance['field_name']); // Switch back to default widget if either: - // - $type_info doesn't exist (the widget type is unknown), + // - the plugin_id is unknown, // - the field type is not allowed for the widget. - if (!isset($definition['class']) || !in_array($field['type'], $definition['field_types'])) { + if (!$definition || !in_array($field['type'], $definition['field_types'])) { // Grab the default widget for the field type. $field_type_definition = field_info_field_types($field['type']); - $type = $field_type_definition['default_widget']; + if (empty($field_type_definition['default_widget'])) { + throw new \RuntimeException(t('No valid widget could be found for field type @type.', array('@type' => $field['type']))); + } + $plugin_id = $field_type_definition['default_widget']; } $configuration = array( @@ -66,7 +69,7 @@ public function getInstance(array $options) { 'settings' => $options['settings'], 'weight' => $options['weight'], ); - return $this->createInstance($type, $configuration); + return $this->createInstance($plugin_id, $configuration); } }