You are here

protected static function FieldableEdgeEntityBase::getBaseFieldDefinition in Apigee Edge 8

Attempts to create a base field definition from a type.

Parameters

string $name: Name of the base field.

string $type: Type of the property.

Return value

\Drupal\Core\Field\BaseFieldDefinition|null Base field definition if found, null otherwise.

1 call to FieldableEdgeEntityBase::getBaseFieldDefinition()
FieldableEdgeEntityBase::baseFieldDefinitions in src/Entity/FieldableEdgeEntityBase.php
Provides base field definitions for an entity type.

File

src/Entity/FieldableEdgeEntityBase.php, line 224

Class

FieldableEdgeEntityBase
Base field support for Apigee Entities without making them content entities.

Namespace

Drupal\apigee_edge\Entity

Code

protected static function getBaseFieldDefinition(string $name, string $type) : ?BaseFieldDefinition {
  $label = ucwords(preg_replace('/([a-z])([A-Z])/', '$1 $2', $name));
  $is_array = strpos($type, 'list_') === 0;
  try {
    $definition = BaseFieldDefinition::create($type);
  } catch (\Exception $ex) {

    // Type not found.
    return NULL;
  }
  $definition
    ->setLabel(t($label));
  $definition
    ->setCardinality($is_array ? FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED : 1);
  $definition
    ->setTranslatable(FALSE);
  $definition
    ->setDisplayConfigurable('view', TRUE);
  $definition
    ->setDisplayConfigurable('form', TRUE);
  return $definition;
}