diff --git a/src/Plugin/Field/FieldType/TypedResourceObjectItem.php b/src/Plugin/Field/FieldType/TypedResourceObjectItem.php index cd89d908811c01d1343e810db67e87283e7f2a40..d7f63b18c9e81713d6a7cd83d76fcd5ee0a3d5f5 100644 --- a/src/Plugin/Field/FieldType/TypedResourceObjectItem.php +++ b/src/Plugin/Field/FieldType/TypedResourceObjectItem.php @@ -6,11 +6,8 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\TypedData\DataDefinition; -use Drupal\Core\TypedData\OptionsProviderInterface; -use Drupal\jsonapi_reference\JsonApiClientInterface; /** * Plugin implementation of the 'typed_resource_object' field type. @@ -24,14 +21,7 @@ use Drupal\jsonapi_reference\JsonApiClientInterface; * default_widget = "typed_resource_object_autocomplete" * ) */ -class TypedResourceObjectItem extends FieldItemBase implements OptionsProviderInterface { - - /** - * The JSON:API client service. - * - * @var \Drupal\jsonapi_reference\JsonApiClientInterface - */ - protected $client; +class TypedResourceObjectItem extends FieldItemBase { /** * {@inheritdoc} @@ -99,7 +89,9 @@ class TypedResourceObjectItem extends FieldItemBase implements OptionsProviderIn public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data): array { $elements = []; - $types = $this->client()->listResourceObjectTypes(); + /** @var \Drupal\jsonapi_reference\JsonApiClientInterface $client */ + $client = \Drupal::service('jsonapi_reference.jsonapi_client'); + $types = $client->listResourceObjectTypes(); $elements['resource_object_type'] = [ '#type' => 'select', @@ -132,19 +124,6 @@ class TypedResourceObjectItem extends FieldItemBase implements OptionsProviderIn return $value === NULL || $value === ''; } - /** - * Gets the JSON:API client service. - * - * @return \Drupal\jsonapi_reference\JsonApiClientInterface - */ - protected function client(): JsonApiClientInterface { - if (!isset($this->client)) { - $this->client = \Drupal::service('jsonapi_reference.jsonapi_client'); - } - - return $this->client; - } - /** * Automatically cast field to a string. * @@ -159,43 +138,4 @@ class TypedResourceObjectItem extends FieldItemBase implements OptionsProviderIn return $this->get('value')->getValue(); } - /** - * {@inheritdoc} - */ - public function getPossibleValues(?AccountInterface $account = NULL): array { - return $this->getSettableValues($account); - } - - /** - * {@inheritdoc} - */ - public function getPossibleOptions(?AccountInterface $account = NULL): array { - return $this->getSettableOptions($account); - } - - /** - * {@inheritdoc} - */ - public function getSettableValues(?AccountInterface $account = NULL): array { - return array_keys($this->getSettableOptions($account)); - } - - /** - * {@inheritdoc} - */ - public function getSettableOptions(?AccountInterface $account = NULL): array { - $options = $this->client()->search( - $this->getSetting('resource_object_type'), - $this->getSetting('title_attribute'), - NULL - ); - - $return = []; - foreach ($options as $option) { - $return[$option[1]] = $option[0]; - } - - return $return; - } - }