public function ConfigurableResourceType::getFieldEnhancer in JSON:API Extras 8
Same name and namespace in other branches
- 8.3 src/ResourceType/ConfigurableResourceType.php \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType::getFieldEnhancer()
- 8.2 src/ResourceType/ConfigurableResourceType.php \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType::getFieldEnhancer()
Get the field enhancer plugin.
Parameters
string $field_name: The internal field name.
string $from: The realm of the provided field name.
Return value
\Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerInterface|null The enhancer plugin. NULL if not found.
File
- src/ResourceType/ ConfigurableResourceType.php, line 164 
Class
- ConfigurableResourceType
- Defines a configurable resource type.
Namespace
Drupal\jsonapi_extras\ResourceTypeCode
public function getFieldEnhancer($field_name, $from = 'fieldName') {
  if (!($resource_field = $this
    ->getResourceFieldConfiguration($field_name, $from))) {
    return NULL;
  }
  if (empty($resource_field['enhancer']['id'])) {
    return NULL;
  }
  try {
    $enhancer_info = $resource_field['enhancer'];
    // Ensure that the settings are in a suitable format.
    $settings = [];
    if (!empty($enhancer_info['settings']) && is_array($enhancer_info['settings'])) {
      $settings = $enhancer_info['settings'];
    }
    // Get the enhancer instance.
    /** @var \Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerInterface $enhancer */
    $enhancer = $this->enhancerManager
      ->createInstance($enhancer_info['id'], $settings);
    return $enhancer;
  } catch (PluginNotFoundException $exception) {
    return NULL;
  }
}