public function OgFieldBase::setEntityType in Organic groups 8
Set the entity type.
Parameters
string $entity_type: The entity type.
Return value
$this
Throws
\Exception Throw error if the field storage config definition explicitly defines to which entities the field can be attached to.
Overrides OgFieldsInterface::setEntityType
File
- src/
OgFieldBase.php, line 61  
Class
- OgFieldBase
 - OG related fields base plugin.
 
Namespace
Drupal\ogCode
public function setEntityType($entity_type) {
  $field_storage = $this
    ->getFieldStorageBaseDefinition();
  if (!empty($field_storage['entity']) && !in_array($entity_type, $field_storage['entity'])) {
    $plugin_id = $this
      ->getPluginId();
    $entities = implode(', ', $field_storage['entity']);
    if ($field_name = $this
      ->getFieldName()) {
      throw new \Exception("The Organic Groups field with plugin ID {$plugin_id} with the name {$field_name} cannot be attached to the entity type. It can only be attached to the following entities: {$entities}.");
    }
    throw new \Exception("The Organic Groups field with plugin ID {$plugin_id} cannot be attached to the entity type. It can only be attached to the following entities: {$entities}.");
  }
  $this->entityType = $entity_type;
  return $this;
}