Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -0,0 +1,14 @@
{{ machine_name }}.{{ entity_type_id }}.*:
type: config_entity
label: {{ entity_type_label }}
mapping:
id:
type: string
label: ID
label:
type: label
label: Label
uuid:
type: string
description:
type: string

View file

@ -0,0 +1,12 @@
name: {{ name }}
type: module
description: 'Provides {{ entity_type_label|article|lower }} configuration entity.'
package: {{ package }}
core: 8.x
{% if dependencies %}
dependencies:
{% for dependency in dependencies %}
- {{ dependency }}
{% endfor %}
{% endif %}
configure: entity.{{ entity_type_id }}.collection

View file

@ -0,0 +1,5 @@
entity.{{ entity_type_id }}.add_form:
route_name: 'entity.{{ entity_type_id }}.add_form'
title: 'Add {{ entity_type_label|lower }}'
appears_on:
- entity.{{ entity_type_id }}.collection

View file

@ -0,0 +1,5 @@
entity.{{ entity_type_id }}.overview:
title: {{ entity_type_label|plural }}
parent: system.admin_structure
description: 'List of {{ entity_type_label|lower|plural }} to extend site functionality.'
route_name: entity.{{ entity_type_id }}.collection

View file

@ -0,0 +1,2 @@
administer {{ entity_type_id }}:
title: 'Administer {{ entity_type_label|lower }}'

View file

@ -0,0 +1,31 @@
entity.{{ entity_type_id }}.collection:
path: '/admin/structure/{{ entity_type_id|u2h }}'
defaults:
_entity_list: '{{ entity_type_id }}'
_title: '{{ entity_type_label }} configuration'
requirements:
_permission: 'administer {{ entity_type_id }}'
entity.{{ entity_type_id }}.add_form:
path: '/admin/structure/{{ entity_type_id }}/add'
defaults:
_entity_form: '{{ entity_type_id }}.add'
_title: 'Add {{ entity_type_label|article|lower }}'
requirements:
_permission: 'administer {{ entity_type_id }}'
entity.{{ entity_type_id }}.edit_form:
path: '/admin/structure/{{ entity_type_id|u2h }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}'
defaults:
_entity_form: '{{ entity_type_id }}.edit'
_title: 'Edit {{ entity_type_label|article|lower }}'
requirements:
_permission: 'administer {{ entity_type_id }}'
entity.{{ entity_type_id }}.delete_form:
path: '/admin/structure/{{ entity_type_id|u2h }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}/delete'
defaults:
_entity_form: '{{ entity_type_id }}.delete'
_title: 'Delete {{ entity_type_label|article|lower }}'
requirements:
_permission: 'administer {{ entity_type_id }}'

View file

@ -0,0 +1,76 @@
<?php
namespace Drupal\{{ machine_name }}\Entity;
{% sort %}
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\{{ machine_name }}\{{ class_prefix }}Interface;
{% endsort %}
/**
* Defines the {{ entity_type_label|lower }} entity type.
*
* @ConfigEntityType(
* id = "{{ entity_type_id }}",
* label = @Translation("{{ entity_type_label }}"),
* label_collection = @Translation("{{ entity_type_label|plural }}"),
* label_singular = @Translation("{{ entity_type_label|lower }}"),
* label_plural = @Translation("{{ entity_type_label|plural|lower }}"),
* label_count = @PluralTranslation(
* singular = "@count {{ entity_type_label|lower }}",
* plural = "@count {{ entity_type_label|plural|lower }}",
* ),
* handlers = {
* "list_builder" = "Drupal\{{ machine_name }}\{{ class_prefix }}ListBuilder",
* "form" = {
* "add" = "Drupal\{{ machine_name }}\Form\{{ class_prefix }}Form",
* "edit" = "Drupal\{{ machine_name }}\Form\{{ class_prefix }}Form",
* "delete" = "Drupal\Core\Entity\EntityDeleteForm"
* }
* },
* config_prefix = "{{ entity_type_id }}",
* admin_permission = "administer {{ entity_type_id }}",
* links = {
* "collection" = "/admin/structure/{{ entity_type_id|u2h }}",
* "add-form" = "/admin/structure/{{ entity_type_id|u2h }}/add",
* "edit-form" = "/admin/structure/{{ entity_type_id|u2h }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}",
* "delete-form" = "/admin/structure/{{ entity_type_id|u2h }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}/delete"
* },
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* }
* )
*/
class {{ class_prefix }} extends ConfigEntityBase implements {{ class_prefix }}Interface {
/**
* The {{ entity_type_label|lower }} ID.
*
* @var string
*/
protected $id;
/**
* The {{ entity_type_label|lower }} label.
*
* @var string
*/
protected $label;
/**
* The {{ entity_type_label|lower }} status.
*
* @var bool
*/
protected $status;
/**
* The {{ entity_type_id|lower }} description.
*
* @var string
*/
protected $description;
}

View file

@ -0,0 +1,12 @@
<?php
namespace Drupal\{{ machine_name }};
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides an interface defining {{ entity_type_label|article|lower }} entity type.
*/
interface {{ class_prefix }}Interface extends ConfigEntityInterface {
}

View file

@ -0,0 +1,34 @@
<?php
namespace Drupal\{{ machine_name }};
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
/**
* Provides a listing of {{ entity_type_label|lower|plural }}.
*/
class {{ class_prefix }}ListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = $this->t('Label');
$header['id'] = $this->t('Machine name');
$header['status'] = $this->t('Status');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/** @var \Drupal\{{ machine_name }}\{{ class_prefix }}Interface $entity */
$row['label'] = $entity->label();
$row['id'] = $entity->id();
$row['status'] = $entity->status() ? $this->t('Enabled') : $this->t('Disabled');
return $row + parent::buildRow($entity);
}
}

View file

@ -0,0 +1,70 @@
<?php
namespace Drupal\{{ machine_name }}\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
/**
* {{ entity_type_label }} form.
*
* @property \Drupal\{{ machine_name }}\{{ class_prefix }}Interface $entity
*/
class {{ class_prefix }}Form extends EntityForm {
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#maxlength' => 255,
'#default_value' => $this->entity->label(),
'#description' => $this->t('Label for the {{ entity_type_label|lower }}.'),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $this->entity->id(),
'#machine_name' => [
'exists' => '\Drupal\{{ machine_name }}\Entity\{{ class_prefix }}::load',
],
'#disabled' => !$this->entity->isNew(),
];
$form['status'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enabled'),
'#default_value' => $this->entity->status(),
];
$form['description'] = [
'#type' => 'textarea',
'#title' => $this->t('Description'),
'#default_value' => $this->entity->get('description'),
'#description' => $this->t('Description of the {{ entity_type_label|lower }}.'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$result = parent::save($form, $form_state);
$message_args = ['%label' => $this->entity->label()];
$message = $result == SAVED_NEW
? $this->t('Created new {{ entity_type_label|lower }} %label.', $message_args)
: $this->t('Updated {{ entity_type_label|lower }} %label.', $message_args);
$this->messenger()->addStatus($message);
$form_state->setRedirectUrl($this->entity->toUrl('collection'));
return $result;
}
}

View file

@ -0,0 +1,31 @@
id: entity.{{ entity_type_id }}
plugin_id: 'entity:{{ entity_type_id }}'
granularity: method
configuration:
GET:
supported_formats:
- json
- xml
supported_auth:
- cookie
POST:
supported_formats:
- json
- xml
supported_auth:
- cookie
PATCH:
supported_formats:
- json
- xml
supported_auth:
- cookie
DELETE:
supported_formats:
- json
- xml
supported_auth:
- cookie
dependencies:
module:
- user

View file

@ -0,0 +1,506 @@
langcode: en
status: true
dependencies:
module:
- {{ machine_name }}
- user
id: {{ entity_type_id }}
label: {{ entity_type_label }}
module: views
description: ''
tag: ''
base_table: {{ entity_type_id }}_field_data
base_field: id
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access {{ entity_type_id }} overview'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Submit
reset_button: true
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: full
options:
items_per_page: 50
offset: 0
id: 0
total_pages: null
tags:
previous:
next:
first: '«'
last: '»'
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
quantity: 9
style:
type: table
options:
grouping: { }
row_class: ''
default_row_class: true
override: true
sticky: false
caption: ''
summary: ''
description: ''
columns:
title: title
bundle: bundle
changed: changed
operations: operations
info:
title:
sortable: true
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: priority-medium
bundle:
sortable: true
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: priority-medium
changed:
sortable: true
default_sort_order: desc
align: ''
separator: ''
empty_column: false
responsive: ''
operations:
align: ''
separator: ''
empty_column: false
responsive: priority-medium
default: changed
empty_table: false
row:
type: fields
fields:
title:
table: {{ entity_type_id }}_field_data
field: title
id: title
entity_type: null
entity_field: title
plugin_id: field
relationship: none
group_type: group
admin_label: ''
label: Title
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: string
settings: { }
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
bundle:
id: bundle
table: {{ entity_type_id }}_field_data
field: bundle
relationship: none
group_type: group
admin_label: ''
label: '{{ entity_type_label }} type'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: target_id
type: entity_reference_label
settings:
link: true
group_column: target_id
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: {{ entity_type_id }}
entity_field: bundle
plugin_id: field
changed:
id: changed
table: {{ entity_type_id }}_field_data
field: changed
relationship: none
group_type: group
admin_label: ''
label: Changed
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: timestamp
settings:
date_format: short
custom_date_format: ''
timezone: ''
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: {{ entity_type_id }}
entity_field: changed
plugin_id: field
operations:
id: operations
table: {{ entity_type_id }}
field: operations
relationship: none
group_type: group
admin_label: ''
label: Operations
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
destination: false
entity_type: {{ entity_type_id }}
plugin_id: entity_operations
filters:
title:
id: title
table: {{ entity_type_id }}_field_data
field: title
relationship: none
group_type: group
admin_label: ''
operator: contains
value: ''
group: 1
exposed: true
expose:
operator_id: title_op
label: Title
description: ''
use_operator: false
operator: title_op
identifier: title
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
anonymous: '0'
placeholder: ''
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
entity_type: {{ entity_type_id }}
entity_field: title
plugin_id: string
bundle:
id: bundle
table: {{ entity_type_id }}_field_data
field: bundle
relationship: none
group_type: group
admin_label: ''
operator: in
value: { }
group: 1
exposed: true
expose:
operator_id: bundle_op
label: '{{ entity_type_label }} type'
description: ''
use_operator: false
operator: bundle_op
identifier: bundle
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
anonymous: '0'
reduce: false
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
entity_type: {{ entity_type_id }}
entity_field: bundle
plugin_id: bundle
sorts: { }
title: {{ entity_type_label }}
header: { }
footer: { }
empty:
area_text_custom:
id: area_text_custom
table: views
field: area_text_custom
relationship: none
group_type: group
admin_label: ''
empty: true
tokenize: false
content: 'No {{ entity_type_id }} available.'
plugin_id: text_custom
relationships: { }
arguments: { }
display_extenders: { }
filter_groups:
operator: AND
groups:
1: AND
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- user.permissions
tags: { }
page:
display_plugin: page
id: page
display_title: Page
position: 1
display_options:
display_extenders: { }
path: admin/content/{{ entity_type_id }}
menu:
type: tab
title: {{ entity_type_label }}
description: ''
expanded: false
parent: ''
weight: 10
context: '0'
menu_name: main
tab_options:
type: normal
title: {{ entity_type_label }}
description: 'Manage and find {{ entity_type_id }}'
weight: 0
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- url.query_args
- user.permissions
tags: { }

View file

@ -0,0 +1,12 @@
{{ machine_name }}.{{ entity_type_id }}_type.*:
type: config_entity
label: '{{ entity_type_label }} type config'
mapping:
id:
type: string
label: 'ID'
label:
type: label
label: 'Label'
uuid:
type: string

View file

@ -0,0 +1,14 @@
name: {{ name }}
type: module
description: 'Provides {{ entity_type_label|article|lower }} entity.'
package: {{ package }}
core: 8.x
{% if dependencies %}
dependencies:
{% for dependency in dependencies %}
- {{ dependency }}
{% endfor %}
{% endif %}
{% if configure %}
configure: {{ configure }}
{% endif %}

View file

@ -0,0 +1,19 @@
{% if bundle %}
{{ entity_type_id }}.type_add:
route_name: entity.{{ entity_type_id }}_type.add_form
title: 'Add {{ entity_type_label|lower }} type'
appears_on:
- entity.{{ entity_type_id }}_type.collection
{{ entity_type_id }}.add_page:
route_name: entity.{{ entity_type_id }}.add_page
title: 'Add {{ entity_type_label|lower }}'
appears_on:
- entity.{{ entity_type_id }}.collection
{% else %}
{{ entity_type_id }}.add_form:
route_name: entity.{{ entity_type_id }}.add_form
title: 'Add {{ entity_type_label|lower }}'
appears_on:
- entity.{{ entity_type_id }}.collection
{% endif %}

View file

@ -0,0 +1,18 @@
{% if fieldable_no_bundle %}
entity.{{ entity_type_id }}.settings:
title: {{ entity_type_label }}
description: Configure {{ entity_type_label|article }} entity type
route_name: entity.{{ entity_type_id }}.settings
parent: system.admin_structure
entity.{{ entity_type_id }}.collection:
title: {{ entity_type_label|plural }}
description: List of {{ entity_type_label|plural|lower }}
route_name: entity.{{ entity_type_id }}.collection
parent: system.admin_content
{% elseif bundle %}
entity.{{ entity_type_id }}_type.collection:
title: '{{ entity_type_label }} types'
parent: system.admin_structure
description: 'Manage and CRUD actions on {{ entity_type_label }} type.'
route_name: entity.{{ entity_type_id }}_type.collection
{% endif %}

View file

@ -0,0 +1,34 @@
{% if fieldable_no_bundle %}
entity.{{ entity_type_id }}.settings:
title: Settings
route_name: entity.{{ entity_type_id }}.settings
base_route: entity.{{ entity_type_id }}.settings
{% endif %}
entity.{{ entity_type_id }}.view:
title: View
route_name: entity.{{ entity_type_id }}.canonical
base_route: entity.{{ entity_type_id }}.canonical
entity.{{ entity_type_id }}.edit_form:
title: Edit
route_name: entity.{{ entity_type_id }}.edit_form
base_route: entity.{{ entity_type_id }}.canonical
entity.{{ entity_type_id }}.delete_form:
title: Delete
route_name: entity.{{ entity_type_id }}.delete_form
base_route: entity.{{ entity_type_id }}.canonical
weight: 10
entity.{{ entity_type_id }}.collection:
title: {{ entity_type_label }}
route_name: entity.{{ entity_type_id }}.collection
base_route: system.admin_content
weight: 10
{% if bundle %}
entity.{{ entity_type_id }}_type.edit_form:
title: Edit
route_name: entity.{{ entity_type_id }}_type.edit_form
base_route: entity.{{ entity_type_id }}_type.edit_form
entity.{{ entity_type_id }}_type.collection:
title: List
route_name: entity.{{ entity_type_id }}_type.collection
base_route: entity.{{ entity_type_id }}_type.collection
{% endif %}

View file

@ -0,0 +1,36 @@
<?php
/**
* @file
* Provides {{ entity_type_label|article|lower }} entity type.
*/
use Drupal\Core\Render\Element;
/**
* Implements hook_theme().
*/
function {{ machine_name }}_theme() {
return [
'{{ entity_type_id }}' => [
'render element' => 'elements',
],
];
}
/**
* Prepares variables for {{ entity_type_label|lower }} templates.
*
* Default template: {{ template_name }}.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the {{ entity_type_label|lower }} information and any
* fields attached to the entity.
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_{{ entity_type_id }}(array &$variables) {
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}

View file

@ -0,0 +1,19 @@
administer {{ entity_type_label|lower }} types:
title: 'Administer {{ entity_type_label|lower }} types'
description: 'Maintain the types of {{ entity_type_label|lower }} entity.'
restrict access: true
administer {{ entity_type_label|lower }}:
title: Administer {{ entity_type_label|lower }} settings
restrict access: true
access {{ entity_type_label|lower }} overview:
title: 'Access {{ entity_type_label|lower }} overview page'
{% if access_controller %}
delete {{ entity_type_label|lower }}:
title: Delete {{ entity_type_label|lower }}
create {{ entity_type_label|lower }}:
title: Create {{ entity_type_label|lower }}
view {{ entity_type_label|lower }}:
title: View {{ entity_type_label|lower }}
edit {{ entity_type_label|lower }}:
title: Edit {{ entity_type_label|lower }}
{% endif %}

View file

@ -0,0 +1,9 @@
{% if fieldable_no_bundle %}
entity.{{ entity_type_id }}.settings:
path: 'admin/structure/{{ entity_type_id|u2h }}'
defaults:
_form: '\Drupal\{{ machine_name }}\Form\{{ class_prefix }}SettingsForm'
_title: '{{ entity_type_label }}'
requirements:
_permission: 'administer {{ entity_type_label|lower }}'
{% endif %}

View file

@ -0,0 +1,354 @@
<?php
namespace Drupal\{{ machine_name }}\Entity;
{% sort %}
{% if not revisionable %}
use Drupal\Core\Entity\ContentEntityBase;
{% endif %}
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
{% if revisionable %}
use Drupal\Core\Entity\RevisionableContentEntityBase;
{% endif %}
use Drupal\{{ machine_name }}\{{ class_prefix }}Interface;
{% if author_base_field %}
use Drupal\user\UserInterface;
{% endif %}
{% if changed_base_field %}
use Drupal\Core\Entity\EntityChangedTrait;
{% endif %}
{% endsort %}
/**
* Defines the {{ entity_type_label|lower }} entity class.
*
* @ContentEntityType(
* id = "{{ entity_type_id }}",
* label = @Translation("{{ entity_type_label }}"),
* label_collection = @Translation("{{ entity_type_label|plural }}"),
{% if bundle %}
* bundle_label = @Translation("{{ entity_type_label }} type"),
{% endif %}
* handlers = {
{% if template %}
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
{% else %}
* "view_builder" = "Drupal\{{ machine_name }}\{{ class_prefix }}ViewBuilder",
{% endif %}
* "list_builder" = "Drupal\{{ machine_name }}\{{ class_prefix }}ListBuilder",
* "views_data" = "Drupal\views\EntityViewsData",
{% if access_controller %}
* "access" = "Drupal\{{ machine_name }}\{{ class_prefix }}AccessControlHandler",
{% endif %}
* "form" = {
* "add" = "Drupal\{{ machine_name }}\Form\{{ class_prefix }}Form",
* "edit" = "Drupal\{{ machine_name }}\Form\{{ class_prefix }}Form",
* "delete" = "Drupal\Core\Entity\ContentEntityDeleteForm"
* },
* "route_provider" = {
* "html" = "Drupal\Core\Entity\Routing\AdminHtmlRouteProvider",
* }
* },
* base_table = "{{ entity_type_id }}",
* data_table = "{{ entity_type_id }}_field_data",
{% if revisionable %}
* revision_table = "{{ entity_type_id }}_revision",
* revision_data_table = "{{ entity_type_id }}_field_revision",
* show_revision_ui = TRUE,
{% endif %}
{% if translatable %}
* translatable = TRUE,
{% endif %}
* admin_permission = "administer {{ entity_type_label|lower }}",
* entity_keys = {
* "id" = "id",
{% if revisionable %}
* "revision" = "revision_id",
{% endif %}
{% if translatable %}
* "langcode" = "langcode",
{% endif %}
{% if bundle %}
* "bundle" = "bundle",
{% endif %}
* "label" = "{{ title_base_field ? 'title' : 'id' }}",
* "uuid" = "uuid"
* },
{% if revisionable %}
* revision_metadata_keys = {
{% if author_base_field %}
* "revision_user" = "revision_uid",
{% endif %}
{% if created_base_field %}
* "revision_created" = "revision_timestamp",
{% endif %}
* "revision_log_message" = "revision_log"
* },
{% endif %}
* links = {
{% if bundle %}
* "add-form" = "{{ entity_base_path }}/add/{{ '{' }}{{ entity_type_id }}{{ '_type}' }}",
* "add-page" = "{{ entity_base_path }}/add",
{% else %}
* "add-form" = "{{ entity_base_path }}/add",
{% endif %}
* "canonical" = "/{{ entity_type_id }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}",
* "edit-form" = "{{ entity_base_path }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}/edit",
* "delete-form" = "{{ entity_base_path }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}/delete",
* "collection" = "/admin/content/{{ entity_type_id|u2h }}"
* },
{% if bundle %}
* bundle_entity_type = "{{ entity_type_id }}_type",
* field_ui_base_route = "entity.{{ entity_type_id }}_type.edit_form"
{% elseif fieldable %}
* field_ui_base_route = "entity.{{ entity_type_id }}.settings"
{% endif %}
* )
*/
class {{ class_prefix }} extends {% if revisionable %}Revisionable{% endif %}ContentEntityBase implements {{ class_prefix }}Interface {
{% if changed_base_field %}
use EntityChangedTrait;
{% endif %}
/**
* {@inheritdoc}
*
* When a new {{ entity_type_label|lower }} entity is created, set the uid entity reference to
* the current user as the creator of the entity.
*/
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
$values += ['uid' => \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('status', $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;
}
}

View file

@ -0,0 +1,61 @@
<?php
namespace Drupal\{{ machine_name }}\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
/**
* Defines the {{ entity_type_label }} type configuration entity.
*
* @ConfigEntityType(
* id = "{{ entity_type_id }}_type",
* label = @Translation("{{ entity_type_label }} type"),
* handlers = {
* "form" = {
* "add" = "Drupal\{{ machine_name }}\Form\{{ class_prefix }}TypeForm",
* "edit" = "Drupal\{{ machine_name }}\Form\{{ class_prefix }}TypeForm",
* "delete" = "Drupal\Core\Entity\EntityDeleteForm",
* },
* "list_builder" = "Drupal\{{ machine_name }}\{{ class_prefix }}TypeListBuilder",
* "route_provider" = {
* "html" = "Drupal\Core\Entity\Routing\AdminHtmlRouteProvider",
* }
* },
* admin_permission = "administer {{ entity_type_label|lower }} types",
* bundle_of = "{{ entity_type_id }}",
* config_prefix = "{{ entity_type_id }}_type",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* },
* links = {
* "add-form" = "/admin/structure/{{ entity_type_id }}_types/add",
* "edit-form" = "/admin/structure/{{ entity_type_id }}_types/manage/{{ '{' ~ entity_type_id ~ '_type}' }}",
* "delete-form" = "/admin/structure/{{ entity_type_id }}_types/manage/{{ '{' ~ entity_type_id ~ '_type}' }}/delete",
* "collection" = "/admin/structure/{{ entity_type_id }}_types"
* },
* config_export = {
* "id",
* "label",
* "uuid",
* }
* )
*/
class {{ class_prefix }}Type extends ConfigEntityBundleBase {
/**
* The machine name of this {{ entity_type_label|lower }} type.
*
* @var string
*/
protected $id;
/**
* The human-readable name of the {{ entity_type_label|lower }} type.
*
* @var string
*/
protected $label;
}

View file

@ -0,0 +1,44 @@
<?php
namespace Drupal\{{ machine_name }};
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Defines the access control handler for the {{ entity_type_label|lower }} entity type.
*/
class {{ class_prefix }}AccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
switch ($operation) {
case 'view':
return AccessResult::allowedIfHasPermission($account, 'view {{ entity_type_label|lower }}');
case 'update':
return AccessResult::allowedIfHasPermissions($account, ['edit {{ entity_type_label|lower }}', 'administer {{ entity_type_label|lower }}'], 'OR');
case 'delete':
return AccessResult::allowedIfHasPermissions($account, ['delete {{ entity_type_label|lower }}', 'administer {{ entity_type_label|lower }}'], 'OR');
default:
// No opinion.
return AccessResult::neutral();
}
}
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermissions($account, ['create {{ entity_type_label|lower }}', 'administer {{ entity_type_label|lower }}'], 'OR');
}
}

View file

@ -0,0 +1,81 @@
<?php
namespace Drupal\{{ machine_name }};
use Drupal\Core\Entity\ContentEntityInterface;
{% if author_base_field %}
use Drupal\user\EntityOwnerInterface;
{% endif %}
{% if changed_base_field %}
use Drupal\Core\Entity\EntityChangedInterface;
{% endif %}
/**
* Provides an interface defining {{ entity_type_label|article|lower }} entity type.
*/
interface {{ class_prefix }}Interface extends ContentEntityInterface{% if author_base_field %}, EntityOwnerInterface{% endif %}{% if changed_base_field %}, EntityChangedInterface{% endif %} {
{% if title_base_field %}
/**
* Gets the {{ entity_type_label|lower }} title.
*
* @return string
* Title of the {{ entity_type_label|lower }}.
*/
public function getTitle();
/**
* Sets the {{ entity_type_label|lower }} title.
*
* @param string $title
* The {{ entity_type_label|lower }} title.
*
* @return \Drupal\{{ machine_name }}\{{ class_prefix }}Interface
* The called {{ entity_type_label|lower }} entity.
*/
public function setTitle($title);
{% endif %}
{% if created_base_field %}
/**
* Gets the {{ entity_type_label|lower }} creation timestamp.
*
* @return int
* Creation timestamp of the {{ entity_type_label|lower }}.
*/
public function getCreatedTime();
/**
* Sets the {{ entity_type_label|lower }} creation timestamp.
*
* @param int $timestamp
* The {{ entity_type_label|lower }} creation timestamp.
*
* @return \Drupal\{{ machine_name }}\{{ class_prefix }}Interface
* The called {{ entity_type_label|lower }} entity.
*/
public function setCreatedTime($timestamp);
{% endif %}
{% if status_base_field %}
/**
* Returns the {{ entity_type_label|lower }} status.
*
* @return bool
* TRUE if the {{ entity_type_label|lower }} is enabled, FALSE otherwise.
*/
public function isEnabled();
/**
* Sets the {{ entity_type_label|lower }} status.
*
* @param bool $status
* TRUE to enable this {{ entity_type_label|lower }}, FALSE to disable.
*
* @return \Drupal\{{ machine_name }}\{{ class_prefix }}Interface
* The called {{ entity_type_label|lower }} entity.
*/
public function setStatus($status);
{% endif %}
}

View file

@ -0,0 +1,138 @@
<?php
namespace Drupal\{{ machine_name }};
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Routing\RedirectDestinationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a list controller for the {{ entity_type_label|lower }} entity type.
*/
class {{ class_prefix }}ListBuilder extends EntityListBuilder {
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* The redirect destination service.
*
* @var \Drupal\Core\Routing\RedirectDestinationInterface
*/
protected $redirectDestination;
/**
* Constructs a new {{ class_prefix }}ListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
* @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
* The redirect destination service.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatterInterface $date_formatter, RedirectDestinationInterface $redirect_destination) {
parent::__construct($entity_type, $storage);
$this->dateFormatter = $date_formatter;
$this->redirectDestination = $redirect_destination;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$entity_type,
$container->get('entity_type.manager')->getStorage($entity_type->id()),
$container->get('date.formatter'),
$container->get('redirect.destination')
);
}
/**
* {@inheritdoc}
*/
public function render() {
$build['table'] = parent::render();
$total = \Drupal::database()
->query('SELECT COUNT(*) FROM {{ '{' }}{{ entity_type_id }}{{ '}' }}')
->fetchField();
$build['summary']['#markup'] = $this->t('Total {{ entity_type_label|lower|plural }}: @total', ['@total' => $total]);
return $build;
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['id'] = $this->t('ID');
{% if title_base_field %}
$header['title'] = $this->t('Title');
{% endif %}
{% if status_base_field %}
$header['status'] = $this->t('Status');
{% endif %}
{% if author_base_field %}
$header['uid'] = $this->t('Author');
{% endif %}
{% if created_base_field %}
$header['created'] = $this->t('Created');
{% endif %}
{% if changed_base_field %}
$header['changed'] = $this->t('Updated');
{% endif %}
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\{{ machine_name }}\Entity\{{ class_prefix }} */
$row['id'] = $entity->{{ title_base_field ? 'id' : 'link' }}();
{% if title_base_field %}
$row['title'] = $entity->link();
{% endif %}
{% if status_base_field %}
$row['status'] = $entity->isEnabled() ? $this->t('Enabled') : $this->t('Disabled');
{% endif %}
{% if author_base_field %}
$row['uid']['data'] = [
'#theme' => 'username',
'#account' => $entity->getOwner(),
];
{% endif %}
{% if created_base_field %}
$row['created'] = $this->dateFormatter->format($entity->getCreatedTime());
{% endif %}
{% if changed_base_field %}
$row['changed'] = $this->dateFormatter->format($entity->getChangedTime());
{% endif %}
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
protected function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
$destination = $this->redirectDestination->getAsArray();
foreach ($operations as $key => $operation) {
$operations[$key]['query'] = $destination;
}
return $operations;
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace Drupal\{{ machine_name }};
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
/**
* Defines a class to build a listing of {{ entity_type_label|lower }} type entities.
*
* @see \Drupal\{{ machine_name }}\Entity\{{ class_prefix }}Type
*/
class {{ class_prefix }}TypeListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['title'] = $this->t('Label');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['title'] = [
'data' => $entity->label(),
'class' => ['menu-label'],
];
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
public function render() {
$build = parent::render();
$build['table']['#empty'] = $this->t(
'No {{ entity_type_label|lower }} types available. <a href=":link">Add {{ entity_type_label|lower }} type</a>.',
[':link' => Url::fromRoute('entity.{{ entity_type_id }}_type.add_form')->toString()]
);
return $build;
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace Drupal\{{ machine_name }};
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityViewBuilder;
/**
* Provides a view controller for {{ entity_type_label|article|lower }} entity type.
*/
class {{ class_prefix }}ViewBuilder extends EntityViewBuilder {
/**
* {@inheritdoc}
*/
protected function getBuildDefaults(EntityInterface $entity, $view_mode) {
$build = parent::getBuildDefaults($entity, $view_mode);
// The {{ entity_type_label|lower }} has no entity template itself.
unset($build['#theme']);
return $build;
}
}

View file

@ -0,0 +1,37 @@
<?php
namespace Drupal\{{ machine_name }}\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
/**
* Form controller for the {{ entity_type_label|lower }} entity edit forms.
*/
class {{ class_prefix }}Form extends ContentEntityForm {
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$entity = $this->getEntity();
$result = $entity->save();
$link = $entity->toLink($this->t('View'))->toRenderable();
$message_arguments = ['%label' => $this->entity->label()];
$logger_arguments = $message_arguments + ['link' => render($link)];
if ($result == SAVED_NEW) {
drupal_set_message($this->t('New {{ entity_type_label|lower }} %label has been created.', $message_arguments));
$this->logger('{{ machine_name }}')->notice('Created new {{ entity_type_label|lower }} %label', $logger_arguments);
}
else {
drupal_set_message($this->t('The {{ entity_type_label|lower }} %label has been updated.', $message_arguments));
$this->logger('{{ machine_name }}')->notice('Created new {{ entity_type_label|lower }} %label.', $logger_arguments);
}
$form_state->setRedirect('entity.{{ entity_type_id }}.canonical', ['{{ entity_type_id }}' => $entity->id()]);
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Drupal\{{ machine_name }}\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Configuration form for {{ entity_type_label|article|lower }} entity type.
*/
class {{ class_prefix }}SettingsForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return '{{ entity_type_id }}_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['settings'] = [
'#markup' => $this->t('Settings form for {{ entity_type_label|article|lower }} entity type.'),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Save'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
drupal_set_message($this->t('The configuration has been updated.'));
}
}

View file

@ -0,0 +1,117 @@
<?php
namespace Drupal\{{ machine_name }}\Form;
use Drupal\Core\Entity\BundleEntityFormBase;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Form handler for {{ entity_type_label|lower }} type forms.
*/
class {{ class_prefix }}TypeForm extends BundleEntityFormBase {
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Constructs the {{ class_prefix }}TypeForm object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(EntityManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager')
);
}
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$entity_type = $this->entity;
if ($this->operation == 'add') {
$form['#title'] = $this->t('Add {{ entity_type_label|lower }} type');
}
else {
$form['#title'] = $this->t(
'Edit %label {{ entity_type_label|lower }} type',
['%label' => $entity_type->label()]
);
}
$form['label'] = [
'#title' => $this->t('Label'),
'#type' => 'textfield',
'#default_value' => $entity_type->label(),
'#description' => $this->t('The human-readable name of this {{ entity_type_label|lower }} type.'),
'#required' => TRUE,
'#size' => 30,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $entity_type->id(),
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
'#machine_name' => [
'exists' => ['Drupal\{{ machine_name }}\Entity\{{ class_prefix }}Type', 'load'],
'source' => ['label'],
],
'#description' => $this->t('A unique machine-readable name for this {{ entity_type_label|lower }} type. It must only contain lowercase letters, numbers, and underscores.'),
];
return $this->protectBundleIdElement($form);
}
/**
* {@inheritdoc}
*/
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = $this->t('Save {{ entity_type_label|lower }} type');
$actions['delete']['#value'] = $this->t('Delete {{ entity_type_label|lower }} type');
return $actions;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$entity_type = $this->entity;
$entity_type->set('id', trim($entity_type->id()));
$entity_type->set('label', trim($entity_type->label()));
$status = $entity_type->save();
$t_args = ['%name' => $entity_type->label()];
if ($status == SAVED_UPDATED) {
$message = 'The {{ entity_type_label|lower }} type %name has been updated.';
}
elseif ($status == SAVED_NEW) {
$message = 'The {{ entity_type_label|lower }} type %name has been added.';
}
drupal_set_message($this->t($message, $t_args));
$this->entityManager->clearCachedFieldDefinitions();
$form_state->setRedirectUrl($entity_type->urlInfo('collection'));
}
}

View file

@ -0,0 +1,21 @@
{{ '{#' }}
/**
* @file
* Default theme implementation to present {{ entity_type_label|article|lower }} entity.
*
* This template is used when viewing a registered {{ entity_type_label|lower }}'s page,
* e.g., {{ entity_base_path }})/123. 123 being the {{ entity_type_label|lower }}'s ID.
*
* Available variables:
* - content: A list of content items. Use 'content' to print all content, or
* print a subset such as 'content.title'.
* - attributes: HTML attributes for the container element.
*
* @see template_preprocess_{{ entity_type_id }}()
*/
{{ '#}' }}{% verbatim %}
<article{{ attributes }}>
{% if content %}
{{- content -}}
{% endif %}
</article>{% endverbatim %}