mdrop_suite-1.0.0-alpha1/modules/mdrop_suite_bundle_field/src/BundleField/MdropSuiteBundleFieldCtaTrait.php
modules/mdrop_suite_bundle_field/src/BundleField/MdropSuiteBundleFieldCtaTrait.php
<?php
namespace Drupal\mdrop_suite_bundle_field\BundleField;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\entity\BundleFieldDefinition;
use Drupal\link\LinkItemInterface;
trait MdropSuiteBundleFieldCtaTrait {
public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions): array {
$fields['mdrop_suite_link'] = BundleFieldDefinition::create('link')
->setName('mdrop_suite_link')
->setLabel(t('Link'))
->setRequired(TRUE)
->setTranslatable(TRUE)
->setCardinality(1)
// @code ->setRevisionable(TRUE) @endcode
->setSettings([
'link_type' => LinkItemInterface::LINK_GENERIC,
'title' => DRUPAL_REQUIRED,
])
// Display.
->setDisplayConfigurable('view', TRUE)
->setDisplayOptions('view', [
'type' => 'link',
'settings' => ['trim_length' => '60'],
'label' => 'hidden',
])
// Form display.
->setDisplayConfigurable('form', TRUE)
->setDisplayOptions('form', [
'type' => 'link_default',
]);
return $fields;
}
}
