pm-4.1.x-dev/modules/pm_organization/src/Entity/PmOrganization.php
modules/pm_organization/src/Entity/PmOrganization.php
<?php
namespace Drupal\pm_organization\Entity;
use CommerceGuys\Addressing\AddressFormat\AddressField;
use CommerceGuys\Addressing\AddressFormat\FieldOverride;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\pm_organization\PmOrganizationInterface;
use Drupal\pm\PmContentEntityBase;
/**
* Defines the Organization entity class.
*
* @ContentEntityType(
* id = "pm_organization",
* label = @Translation("Organization"),
* label_collection = @Translation("Organizations"),
* label_singular = @Translation("Organization"),
* label_plural = @Translation("Organizations"),
* label_count = @PluralTranslation(
* singular = "@count Organizations",
* plural = "@count Organizations",
* ),
* bundle_label = @Translation("Organization type"),
* handlers = {
* "list_builder" = "Drupal\pm_organization\PmOrganizationListBuilder",
* "views_data" = "Drupal\views\EntityViewsData",
* "access" = "Drupal\pm_organization\PmOrganizationAccessControlHandler",
* "form" = {
* "add" = "Drupal\pm_organization\Form\PmOrganizationForm",
* "edit" = "Drupal\pm_organization\Form\PmOrganizationForm",
* "delete" = "Drupal\Core\Entity\ContentEntityDeleteForm",
* },
* "route_provider" = {
* "html" = "Drupal\Core\Entity\Routing\AdminHtmlRouteProvider",
* }
* },
* base_table = "pm_organization",
* admin_permission = "administer pm organization types",
* entity_keys = {
* "id" = "id",
* "bundle" = "bundle",
* "label" = "label",
* "uuid" = "uuid",
* "owner" = "uid",
* },
* links = {
* "collection" = "/admin/pm/organization",
* "add-form" = "/pm/organization/add/{pm_organization_type}",
* "add-page" = "/pm/organization/add",
* "canonical" = "/pm/organization/{pm_organization}",
* "edit-form" = "/pm/organization/{pm_organization}/edit",
* "delete-form" = "/pm/organization/{pm_organization}/delete",
* },
* bundle_entity_type = "pm_organization_type",
* field_ui_base_route = "entity.pm_organization_type.edit_form",
* )
*/
class PmOrganization extends PmContentEntityBase implements PmOrganizationInterface {
/**
* {@inheritdoc}
*/
public static function getPmContentEntityBaseFieldNames() {
return [
'pm_project_list',
'pm_member_list',
];
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['pm_mail'] = BaseFieldDefinition::create('email')
->setLabel(t('Email'))
->setRequired(FALSE)
->setDisplayOptions('form', [
'type' => 'email_default',
'weight' => 1,
])
->setSetting('display_description', TRUE)
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE);
$fields['pm_telephone'] = BaseFieldDefinition::create('telephone')
->setLabel(t('Telephone'))
->setRequired(FALSE)
->setDisplayOptions('form', [
'type' => 'telephone_default',
'weight' => 2,
])
->setSetting('display_description', TRUE)
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE);
$fields['pm_address'] = BaseFieldDefinition::create('address')
->setLabel(t('Address'))
->setCardinality(1)
->setRequired(FALSE)
->setSetting('field_overrides', [
AddressField::GIVEN_NAME => ['override' => FieldOverride::HIDDEN],
AddressField::ADDITIONAL_NAME => ['override' => FieldOverride::HIDDEN],
AddressField::FAMILY_NAME => ['override' => FieldOverride::HIDDEN],
AddressField::ORGANIZATION => ['override' => FieldOverride::HIDDEN],
])
->setDisplayOptions('form', [
'type' => 'address_default',
'weight' => 4,
])
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE);
return $fields;
}
}
