View source
<?php
declare (strict_types=1);
namespace Drupal\og;
use Drupal\Core\Plugin\PluginBase;
abstract class OgFieldBase extends PluginBase implements OgFieldsInterface {
protected $bundle;
protected $entityType;
protected $fieldName;
public function setBundle($bundle) {
$this->bundle = $bundle;
return $this;
}
public function getBundle() {
return $this->bundle;
}
public function getEntityType() {
return $this->entityType;
}
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;
}
public function getFieldName() {
return $this->fieldName;
}
public function setFieldName($field_name) {
$this->fieldName = $field_name;
return $this;
}
public function getFieldStorageBaseDefinition(array $values = []) {
$values += [
'entity_type' => $this
->getEntityType(),
'field_name' => $this
->getFieldName(),
];
return $values;
}
public function getFieldBaseDefinition(array $values = []) {
$values += [
'bundle' => $this
->getBundle(),
'entity_type' => $this
->getEntityType(),
'field_name' => $this
->getFieldName(),
];
return $values;
}
}