You are here

public static function ResourceFieldEntity::fieldClassName in RESTful 7.2

Get the class name to use based on the field definition.

Parameters

array $field_definition: The processed field definition with the user values.

Return value

string The class name to use. If the class name is empty or does not implement ResourceFieldInterface then ResourceField will be used. NULL if nothing was found.

2 calls to ResourceFieldEntity::fieldClassName()
ResourceEntity::processPublicFields in src/Plugin/resource/ResourceEntity.php
Get the public fields with the default values applied to them.
ResourceFieldEntity::create in src/Plugin/resource/Field/ResourceFieldEntity.php
Factory.

File

src/Plugin/resource/Field/ResourceFieldEntity.php, line 910
Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldEntity

Class

ResourceFieldEntity
Class ResourceFieldEntity.

Namespace

Drupal\restful\Plugin\resource\Field

Code

public static function fieldClassName(array $field_definition) {
  if (!empty($field_definition['class']) && $field_definition['class'] != '\\Drupal\\restful\\Plugin\\resource\\Field\\ResourceFieldEntity') {

    // If there is a class that is not the current, return it.
    return $field_definition['class'];
  }

  // If there is an extending class for the particular field use that class
  // instead.
  if (empty($field_definition['property']) || !($field_info = static::fieldInfoField($field_definition['property']))) {
    return NULL;
  }
  switch ($field_info['type']) {
    case 'entityreference':
    case 'taxonomy_term_reference':
      return '\\Drupal\\restful\\Plugin\\resource\\Field\\ResourceFieldEntityReference';
    case 'text':
    case 'text_long':
    case 'text_with_summary':
      return '\\Drupal\\restful\\Plugin\\resource\\Field\\ResourceFieldEntityText';
    case 'file':
    case 'image':

      // If the field is treated as a resource, then default to the reference.
      if (!empty($field_definition['resource'])) {
        return '\\Drupal\\restful\\Plugin\\resource\\Field\\ResourceFieldFileEntityReference';
      }
      return '\\Drupal\\restful\\Plugin\\resource\\Field\\ResourceFieldEntityFile';
    default:
      return NULL;
  }
}