public function UpdateHelper::checkBodyField in Menu Item Extras 8.2
Creates or load field.
Parameters
\Drupal\Core\Entity\EntityInterface $field_storage: Field storage instance.
\Drupal\Core\Entity\EntityInterface $entity: Entity instance.
string $field_name: Field name.
string $label: Label for field.
mixed[] $settings: Field settings.
Return value
\Drupal\Core\Entity\EntityInterface|static Field instance.
File
- src/
Service/ UpdateHelper.php, line 63
Class
- UpdateHelper
- Class MenuLinkContentUpdateHelper.
Namespace
Drupal\menu_item_extras\ServiceCode
public function checkBodyField(EntityInterface $field_storage, EntityInterface $entity, $field_name, $label, array $settings) {
$field = FieldConfig::loadByName($entity
->getEntityTypeId(), $entity
->bundle(), $field_name);
if (empty($field)) {
$field = FieldConfig::create([
'field_name' => $field_name,
'entity_type' => $entity
->getEntityTypeId(),
'field_storage' => $field_storage,
'bundle' => $entity
->bundle(),
'label' => $label,
'settings' => $settings,
]);
$field
->save();
}
return $field;
}