X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fmodule%2Fcontent-entity%2Fsrc%2FEntity%2FExample.php.twig;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fmodule%2Fcontent-entity%2Fsrc%2FEntity%2FExample.php.twig;h=4955455c7d5351198e1bf84514be15de59a10687;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=0000000000000000000000000000000000000000;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0;p=yaffs-website diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/module/content-entity/src/Entity/Example.php.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/module/content-entity/src/Entity/Example.php.twig new file mode 100755 index 000000000..4955455c7 --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/templates/d8/module/content-entity/src/Entity/Example.php.twig @@ -0,0 +1,334 @@ + \Drupal::currentUser()->id()]; + } + +{% if title_base_field %} + /** + * {@inheritdoc} + */ + public function getTitle() { + return $this->get('title')->value; + } + + /** + * {@inheritdoc} + */ + public function setTitle($title) { + $this->set('title', $title); + return $this; + } + +{% endif %} +{% if status_base_field %} + /** + * {@inheritdoc} + */ + public function isEnabled() { + return (bool) $this->get('status')->value; + } + + /** + * {@inheritdoc} + */ + public function setStatus($status) { + $this->set('promote', $status); + return $this; + } + +{% endif %} +{% if created_base_field %} + /** + * {@inheritdoc} + */ + public function getCreatedTime() { + return $this->get('created')->value; + } + + /** + * {@inheritdoc} + */ + public function setCreatedTime($timestamp) { + $this->set('created', $timestamp); + return $this; + } + +{% endif %} +{% if author_base_field %} + /** + * {@inheritdoc} + */ + public function getOwner() { + return $this->get('uid')->entity; + } + + /** + * {@inheritdoc} + */ + public function getOwnerId() { + return $this->get('uid')->target_id; + } + + /** + * {@inheritdoc} + */ + public function setOwnerId($uid) { + $this->set('uid', $uid); + return $this; + } + + /** + * {@inheritdoc} + */ + public function setOwner(UserInterface $account) { + $this->set('uid', $account->id()); + return $this; + } + +{% endif %} + /** + * {@inheritdoc} + */ + public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { + + $fields = parent::baseFieldDefinitions($entity_type); + +{% if title_base_field %} + $fields['title'] = BaseFieldDefinition::create('string') +{% if revisionable %} + ->setRevisionable(TRUE) +{% endif %} +{% if translatable %} + ->setTranslatable(TRUE) +{% endif %} + ->setLabel(t('Title')) + ->setDescription(t('The title of the {{ entity_type_label|lower }} entity.')) + ->setRequired(TRUE) + ->setSetting('max_length', 255) + ->setDisplayOptions('form', [ + 'type' => 'string_textfield', + 'weight' => -5, + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayOptions('view', [ + 'label' => 'hidden', + 'type' => 'string', + 'weight' => -5, + ]) + ->setDisplayConfigurable('view', TRUE); + +{% endif %} +{% if status_base_field %} + $fields['status'] = BaseFieldDefinition::create('boolean') +{% if revisionable %} + ->setRevisionable(TRUE) +{% endif %} + ->setLabel(t('Status')) + ->setDescription(t('A boolean indicating whether the {{ entity_type_label|lower }} is enabled.')) + ->setDefaultValue(TRUE) + ->setSetting('on_label', 'Enabled') + ->setDisplayOptions('form', [ + 'type' => 'boolean_checkbox', + 'settings' => [ + 'display_label' => FALSE, + ], + 'weight' => 0, + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayOptions('view', [ + 'type' => 'boolean', + 'label' => 'above', + 'weight' => 0, + 'settings' => [ + 'format' => 'enabled-disabled', + ], + ]) + ->setDisplayConfigurable('view', TRUE); + +{% endif %} +{% if description_base_field %} + $fields['description'] = BaseFieldDefinition::create('text_long') +{% if revisionable %} + ->setRevisionable(TRUE) +{% endif %} +{% if translatable %} + ->setTranslatable(TRUE) +{% endif %} + ->setLabel(t('Description')) + ->setDescription(t('A description of the {{ entity_type_label|lower }}.')) + ->setDisplayOptions('form', [ + 'type' => 'text_textarea', + 'weight' => 10, + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayOptions('view', [ + 'type' => 'text_default', + 'label' => 'above', + 'weight' => 10, + ]) + ->setDisplayConfigurable('view', TRUE); + +{% endif %} +{% if author_base_field %} + $fields['uid'] = BaseFieldDefinition::create('entity_reference') +{% if revisionable %} + ->setRevisionable(TRUE) +{% endif %} +{% if translatable %} + ->setTranslatable(TRUE) +{% endif %} + ->setLabel(t('Author')) + ->setDescription(t('The user ID of the {{ entity_type_label|lower }} author.')) + ->setSetting('target_type', 'user') + ->setDisplayOptions('form', [ + 'type' => 'entity_reference_autocomplete', + 'settings' => [ + 'match_operator' => 'CONTAINS', + 'size' => 60, + 'placeholder' => '', + ], + 'weight' => 15, + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayOptions('view', [ + 'label' => 'above', + 'type' => 'author', + 'weight' => 15, + ]) + ->setDisplayConfigurable('view', TRUE); + +{% endif %} +{% if created_base_field %} + $fields['created'] = BaseFieldDefinition::create('created') + ->setLabel(t('Authored on')) +{% if translatable %} + ->setTranslatable(TRUE) +{% endif %} + ->setDescription(t('The time that the {{ entity_type_label|lower }} was created.')) + ->setDisplayOptions('view', [ + 'label' => 'above', + 'type' => 'timestamp', + 'weight' => 20, + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayOptions('form', [ + 'type' => 'datetime_timestamp', + 'weight' => 20, + ]) + ->setDisplayConfigurable('view', TRUE); + +{% endif %} +{% if changed_base_field %} + $fields['changed'] = BaseFieldDefinition::create('changed') + ->setLabel(t('Changed')) +{% if translatable %} + ->setTranslatable(TRUE) +{% endif %} + ->setDescription(t('The time that the {{ entity_type_label|lower }} was last edited.')); + +{% endif %} + return $fields; + } + +}