class CerProfile2Field in Corresponding Entity References 7.3
@file Contains a CER field plugin for referencing Profile2 entities. These references are not actually fields at all, so this plugin is really more of a bridge to trick CER into thinking that Profile2 is a reference field.
Hierarchy
- class \FieldInstance
- class \CerField
- class \CerProfile2Field implements CerEntityContainerInterface
- class \CerField
Expanded class hierarchy of CerProfile2Field
1 string reference to 'CerProfile2Field'
- cer_profile2_cer_fields in extensions/
cer_profile2/ cer_profile2.cer.inc - Implements hook_cer_fields().
File
- extensions/
cer_profile2/ profile2.inc, line 10 - Contains a CER field plugin for referencing Profile2 entities. These references are not actually fields at all, so this plugin is really more of a bridge to trick CER into thinking that Profile2 is a reference field.
View source
class CerProfile2Field extends CerField implements CerEntityContainerInterface {
protected $profileType;
/**
* @override CerField::__construct().
*/
public function __construct(array $plugin) {
$this->plugin = $plugin;
list($this->entityType, $this->bundle, $this->name) = explode(':', $plugin['identifier']);
$info = entity_get_info($this->entityType);
// These "fields" can only be instantiated on user accounts, which are
// normally not bundleable. However, there could be a module in the wild
// which makes accounts bundleable, so let's not be presumptuous here.
$this->isBundleable = (bool) $info['entity keys']['bundle'];
$this->entityTypeLabel = $info['label'];
$this->bundleLabel = $info['bundles'][$this->bundle]['label'];
// An account can only have one profile of this type.
$this->cardinality = 1;
$this->fieldTypeLabel = t('Profile');
// Load the Profile2 type information
$this->profileType = profile2_get_types(subStr($this->name, 8));
$this->label = $this->profileType->label;
}
/**
* Implements CerField::getTargetType().
*/
public function getTargetType() {
// In effect, this "field" will "point to" Profile2 entities.
return 'profile2';
}
/**
* @override CerField::getTargetBundles().
*/
public function getTargetBundles() {
// This field can only "reference" one type of profile. There'll be
// a separate instance of this plugin for each Profile2 type.
return (array) $this->profileType->type;
}
/**
* Implements CerEntityContainerInterface::createInnerEntity().
*/
public function createInnerEntity(EntityDrupalWrapper $owner) {
$init = array(
'user' => $owner
->value(),
'type' => $this->profileType,
);
// Create a blank profile for this user, and save it. The "reference" is implied
// by the existence of the profile.
$profile = profile2_create($init);
$profile
->save();
return $profile;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CerField:: |
public | property | ||
CerField:: |
protected | property | The plugin definition. | |
CerField:: |
protected | property | ||
CerField:: |
public | function | Returns a CerFieldHandler subclass instance for the given entity. | |
CerField:: |
public | function |
Overridden. Overrides FieldInstance:: |
|
CerField:: |
public static | function | Returns a single field plugin instance, by its identifier. All plugin instances are statically cached. | |
CerField:: |
public static | function | Returns information about a particular field plugin by its identifier, or all available plugins (i.e., defined by hook_cer_fields()) if no identifier is given. The aggregated result of hook_cer_fields() is statically cached. | |
CerField:: |
public | function |
Overridden. Overrides FieldInstance:: |
|
CerProfile2Field:: |
protected | property | ||
CerProfile2Field:: |
public | function |
Implements CerEntityContainerInterface::createInnerEntity(). Overrides CerEntityContainerInterface:: |
|
CerProfile2Field:: |
public | function |
@override CerField::getTargetBundles(). Overrides CerField:: |
|
CerProfile2Field:: |
public | function |
Implements CerField::getTargetType(). Overrides CerField:: |
|
CerProfile2Field:: |
public | function |
@override CerField::__construct(). Overrides CerField:: |
|
FieldInstance:: |
public | property | The instance bundle. | |
FieldInstance:: |
public | property | The human-readable label of the instance's bundle. | |
FieldInstance:: |
public | property | The cardinality (maximum values) the field supports, or FIELD_CARDINALITY_UNLIMITED. | |
FieldInstance:: |
protected | property | The child of this instance, if any. | |
FieldInstance:: |
public | property | The instance's entity type. | |
FieldInstance:: |
public | property | The human-readable label of the instance's entity type. | |
FieldInstance:: |
public | property | Whether or not this instance's entity type supports bundles. | |
FieldInstance:: |
public | property | The instance's label. | |
FieldInstance:: |
public | property | The field's machine name. | |
FieldInstance:: |
protected | property | The parent of this instance, if any. | |
FieldInstance:: |
public | function | Get or set the child of this field instance. | |
FieldInstance:: |
public | function | Get or set the parent of this field instance. | |
FieldInstance:: |
public | function |