protected function PbfBaseTest::createPbfField in Permissions by field 8
Creates a field of an Pbf field storage on the specified bundle.
Parameters
string $entity_type: The type of entity the field will be attached to.
string $bundle: The bundle name of the entity the field will be attached to.
string $field_name: The name of the field; if it already exists, a new instance of the existing field will be created.
string $field_label: The label of the field.
string $target_entity_type: The type of the referenced entity.
string $selection_handler: The selection handler used by this field.
array $selection_handler_settings: An array of settings supported by the selection handler specified above. (e.g. 'target_bundles', 'sort', 'auto_create', etc).
int $cardinality: The cardinality of the field.
string $user_method: The method used for granting access to user.
int $priority: The priority access.
string $synchronized_with: The field is synchronized with another Pbf field.
int $synchronized_from_target: The synchronized targeted field can synchronize the source.
Return value
\Drupal\field\Entity\FieldConfig $field The field created or loaded.
See also
\Drupal\Core\Entity\Plugin\EntityReferenceSelection\SelectionBase::buildConfigurationForm()
5 calls to PbfBaseTest::createPbfField()
- PbfBaseTest::attachPbfNodeFields in tests/
src/ Functional/ PbfBaseTest.php - Helper function to create and attach a Pbf Node field.
- PbfBaseTest::attachPbfRoleFields in tests/
src/ Functional/ PbfBaseTest.php - Helper function to create and attach a Pbf Role field.
- PbfBaseTest::attachPbfSynchronizedFields in tests/
src/ Functional/ PbfBaseTest.php - Helper function to create and attach a Pbf Node field synchronized.
- PbfBaseTest::attachPbfTermFields in tests/
src/ Functional/ PbfBaseTest.php - Attach Pbf fields which reference taxonomy terms.
- PbfBaseTest::attachPbfUserFields in tests/
src/ Functional/ PbfBaseTest.php - Attach Pbf fields which reference Users.
File
- tests/
src/ Functional/ PbfBaseTest.php, line 265
Class
- PbfBaseTest
- General setup and helper function for testing pbf module.
Namespace
Drupal\Tests\pbf\FunctionalCode
protected function createPbfField($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = array(), $cardinality = -1, $user_method = 'user', $priority = 0, $synchronized_with = '', $synchronized_from_target = 0) {
// Look for or add the specified field to the requested entity bundle.
if (!FieldStorageConfig::loadByName($entity_type, $field_name)) {
FieldStorageConfig::create(array(
'field_name' => $field_name,
'type' => 'pbf',
'entity_type' => $entity_type,
'cardinality' => $cardinality,
'settings' => array(
'target_type' => $target_entity_type,
),
))
->save();
}
if (!FieldConfig::loadByName($entity_type, $bundle, $field_name)) {
FieldConfig::create(array(
'field_name' => $field_name,
'entity_type' => $entity_type,
'bundle' => $bundle,
'label' => $field_label,
'settings' => array(
'handler' => $selection_handler,
'handler_settings' => $selection_handler_settings,
'priority' => $priority,
'user_method' => $user_method,
'synchronized_with' => $synchronized_with,
'synchronized_form_target' => $synchronized_from_target,
),
))
->save();
}
$field = FieldConfig::loadByName($entity_type, $bundle, $field_name);
return $field;
}