Commit ab63e972 authored by catch's avatar catch
Browse files

Issue #3275585 by dspachos, apaderno, joachim: Implementations of...

Issue #3275585 by dspachos, apaderno, joachim: Implementations of getInstance() return the wrong type

(cherry picked from commit d9b8a31b)
parent d19fa67a
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -90,8 +90,8 @@ public function createInstance($plugin_id, array $configuration = []) {
   *     - 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.
   * @return \Drupal\Core\Field\FormatterInterface|false
   *   A formatter object or FALSE when plugin is not found.
   */
  public function getInstance(array $options) {
    $configuration = $options['configuration'];
@@ -114,7 +114,7 @@ public function getInstance(array $options) {
      // Grab the default widget for the field type.
      $field_type_definition = $this->fieldTypeManager->getDefinition($field_type);
      if (empty($field_type_definition['default_formatter'])) {
        return NULL;
        return FALSE;
      }
      $plugin_id = $field_type_definition['default_formatter'];
    }
@@ -123,7 +123,7 @@ public function getInstance(array $options) {
      'field_definition' => $field_definition,
      'view_mode' => $options['view_mode'],
    ];
    return $this->createInstance($plugin_id, $configuration);
    return $this->createInstance($plugin_id, $configuration) ?? FALSE;
  }

  /**
+4 −4
Original line number Diff line number Diff line
@@ -69,8 +69,8 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
   *     - 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.
   * @return \Drupal\Core\Field\WidgetInterface|false
   *   A Widget object or FALSE when plugin is not found.
   */
  public function getInstance(array $options) {
    // Fill in defaults for missing properties.
@@ -99,7 +99,7 @@ public function getInstance(array $options) {
      // Grab the default widget for the field type.
      $field_type_definition = $this->fieldTypeManager->getDefinition($field_type);
      if (empty($field_type_definition['default_widget'])) {
        return NULL;
        return FALSE;
      }
      $plugin_id = $field_type_definition['default_widget'];
    }
@@ -107,7 +107,7 @@ public function getInstance(array $options) {
    $configuration += [
      'field_definition' => $field_definition,
    ];
    return $this->createInstance($plugin_id, $configuration);
    return $this->createInstance($plugin_id, $configuration) ?? FALSE;
  }

  /**