generated Organisation entity
This commit is contained in:
parent
17f8ddba2e
commit
675a85dfb6
@ -0,0 +1,12 @@
|
|||||||
|
opencase_entities.oc_organisation_type.*:
|
||||||
|
type: config_entity
|
||||||
|
label: 'Organisation type config'
|
||||||
|
mapping:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
label: 'ID'
|
||||||
|
label:
|
||||||
|
type: label
|
||||||
|
label: 'Label'
|
||||||
|
uuid:
|
||||||
|
type: string
|
30
modules/opencase_entities/oc_organisation.page.inc
Normal file
30
modules/opencase_entities/oc_organisation.page.inc
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Contains oc_organisation.page.inc.
|
||||||
|
*
|
||||||
|
* Page callback for Organisation entities.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Drupal\Core\Render\Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepares variables for Organisation templates.
|
||||||
|
*
|
||||||
|
* Default template: oc_organisation.html.twig.
|
||||||
|
*
|
||||||
|
* @param array $variables
|
||||||
|
* An associative array containing:
|
||||||
|
* - elements: An associative array containing the user information and any
|
||||||
|
* - attributes: HTML attributes for the containing element.
|
||||||
|
*/
|
||||||
|
function template_preprocess_oc_organisation(array &$variables) {
|
||||||
|
// Fetch OCOrganisation Entity Object.
|
||||||
|
$oc_organisation = $variables['elements']['#oc_organisation'];
|
||||||
|
|
||||||
|
// Helpful $content variable for templates.
|
||||||
|
foreach (Element::children($variables['elements']) as $key) {
|
||||||
|
$variables['content'][$key] = $variables['elements'][$key];
|
||||||
|
}
|
||||||
|
}
|
@ -31,3 +31,13 @@ entity.oc_activity_type.add_form:
|
|||||||
appears_on:
|
appears_on:
|
||||||
- entity.oc_activity_type.collection
|
- entity.oc_activity_type.collection
|
||||||
|
|
||||||
|
entity.oc_organisation.add_form:
|
||||||
|
route_name: entity.oc_organisation.add_page
|
||||||
|
title: 'Add Organisation'
|
||||||
|
appears_on:
|
||||||
|
- entity.oc_organisation.collection
|
||||||
|
entity.oc_organisation_type.add_form:
|
||||||
|
route_name: entity.oc_organisation_type.add_form
|
||||||
|
title: 'Add Organisation type'
|
||||||
|
appears_on:
|
||||||
|
- entity.oc_organisation_type.collection
|
||||||
|
@ -52,3 +52,20 @@ entity.oc_activity_type.collection:
|
|||||||
parent: system.admin_structure
|
parent: system.admin_structure
|
||||||
weight: 99
|
weight: 99
|
||||||
|
|
||||||
|
|
||||||
|
# Organisation menu items definition
|
||||||
|
entity.oc_organisation.collection:
|
||||||
|
title: 'Organisation list'
|
||||||
|
route_name: entity.oc_organisation.collection
|
||||||
|
description: 'List Organisation entities'
|
||||||
|
parent: system.admin_structure
|
||||||
|
weight: 100
|
||||||
|
|
||||||
|
|
||||||
|
# Organisation type menu items definition
|
||||||
|
entity.oc_organisation_type.collection:
|
||||||
|
title: 'Organisation type'
|
||||||
|
route_name: entity.oc_organisation_type.collection
|
||||||
|
description: 'List Organisation type (bundles)'
|
||||||
|
parent: system.admin_structure
|
||||||
|
weight: 99
|
||||||
|
@ -67,3 +67,25 @@ entity.oc_activity.delete_form:
|
|||||||
title: Delete
|
title: Delete
|
||||||
weight: 10
|
weight: 10
|
||||||
|
|
||||||
|
# Organisation routing definition
|
||||||
|
|
||||||
|
entity.oc_organisation.canonical:
|
||||||
|
route_name: entity.oc_organisation.canonical
|
||||||
|
base_route: entity.oc_organisation.canonical
|
||||||
|
title: 'View'
|
||||||
|
|
||||||
|
entity.oc_organisation.edit_form:
|
||||||
|
route_name: entity.oc_organisation.edit_form
|
||||||
|
base_route: entity.oc_organisation.canonical
|
||||||
|
title: 'Edit'
|
||||||
|
|
||||||
|
entity.oc_organisation.version_history:
|
||||||
|
route_name: entity.oc_organisation.version_history
|
||||||
|
base_route: entity.oc_organisation.canonical
|
||||||
|
title: 'Revisions'
|
||||||
|
|
||||||
|
entity.oc_organisation.delete_form:
|
||||||
|
route_name: entity.oc_organisation.delete_form
|
||||||
|
base_route: entity.oc_organisation.canonical
|
||||||
|
title: Delete
|
||||||
|
weight: 10
|
||||||
|
@ -62,6 +62,16 @@ function opencase_entities_theme() {
|
|||||||
'variables' => ['content' => NULL],
|
'variables' => ['content' => NULL],
|
||||||
'file' => 'oc_activity.page.inc',
|
'file' => 'oc_activity.page.inc',
|
||||||
];
|
];
|
||||||
|
$theme['oc_organisation'] = [
|
||||||
|
'render element' => 'elements',
|
||||||
|
'file' => 'oc_organisation.page.inc',
|
||||||
|
'template' => 'oc_organisation',
|
||||||
|
];
|
||||||
|
$theme['oc_organisation_content_add_list'] = [
|
||||||
|
'render element' => 'content',
|
||||||
|
'variables' => ['content' => NULL],
|
||||||
|
'file' => 'oc_organisation.page.inc',
|
||||||
|
];
|
||||||
return $theme;
|
return $theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,3 +149,19 @@ function opencase_query_oc_activity_access_alter($query) {
|
|||||||
$query->addJoin('INNER', 'oc_case__actors_involved', 'access_filter', 'access_filter.entity_id = oc_activity_field_data.oc_case');
|
$query->addJoin('INNER', 'oc_case__actors_involved', 'access_filter', 'access_filter.entity_id = oc_activity_field_data.oc_case');
|
||||||
$query->condition('access_filter.actors_involved_target_id', $linked_actor_id);
|
$query->condition('access_filter.actors_involved_target_id', $linked_actor_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_theme_suggestions_HOOK().
|
||||||
|
*/
|
||||||
|
function opencase_entities_theme_suggestions_oc_organisation(array $variables) {
|
||||||
|
$suggestions = [];
|
||||||
|
$entity = $variables['elements']['#oc_organisation'];
|
||||||
|
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
|
||||||
|
|
||||||
|
$suggestions[] = 'oc_organisation__' . $sanitized_view_mode;
|
||||||
|
$suggestions[] = 'oc_organisation__' . $entity->bundle();
|
||||||
|
$suggestions[] = 'oc_organisation__' . $entity->bundle() . '__' . $sanitized_view_mode;
|
||||||
|
$suggestions[] = 'oc_organisation__' . $entity->id();
|
||||||
|
$suggestions[] = 'oc_organisation__' . $entity->id() . '__' . $sanitized_view_mode;
|
||||||
|
return $suggestions;
|
||||||
|
}
|
||||||
|
@ -72,3 +72,36 @@ revert all activity revisions:
|
|||||||
delete all activity revisions:
|
delete all activity revisions:
|
||||||
title: 'Delete all revisions'
|
title: 'Delete all revisions'
|
||||||
description: 'Role requires permission to <em>view Activity revisions</em> and <em>delete rights</em> for activity entities in question or <em>administer activity entities</em>.'
|
description: 'Role requires permission to <em>view Activity revisions</em> and <em>delete rights</em> for activity entities in question or <em>administer activity entities</em>.'
|
||||||
|
add organisation entities:
|
||||||
|
title: 'Create new Organisation entities'
|
||||||
|
|
||||||
|
administer organisation entities:
|
||||||
|
title: 'Administer Organisation entities'
|
||||||
|
description: 'Allow to access the administration form to configure Organisation entities.'
|
||||||
|
restrict access: true
|
||||||
|
|
||||||
|
delete organisation entities:
|
||||||
|
title: 'Delete Organisation entities'
|
||||||
|
|
||||||
|
edit organisation entities:
|
||||||
|
title: 'Edit Organisation entities'
|
||||||
|
|
||||||
|
view published organisation entities:
|
||||||
|
title: 'View published Organisation entities'
|
||||||
|
|
||||||
|
view unpublished organisation entities:
|
||||||
|
title: 'View unpublished Organisation entities'
|
||||||
|
|
||||||
|
view all organisation revisions:
|
||||||
|
title: 'View all Organisation revisions'
|
||||||
|
|
||||||
|
revert all organisation revisions:
|
||||||
|
title: 'Revert all Organisation revisions'
|
||||||
|
description: 'Role requires permission <em>view Organisation revisions</em> and <em>edit rights</em> for organisation entities in question or <em>administer organisation entities</em>.'
|
||||||
|
|
||||||
|
delete all organisation revisions:
|
||||||
|
title: 'Delete all revisions'
|
||||||
|
description: 'Role requires permission to <em>view Organisation revisions</em> and <em>delete rights</em> for organisation entities in question or <em>administer organisation entities</em>.'
|
||||||
|
|
||||||
|
permission_callbacks:
|
||||||
|
- \Drupal\opencase_entities\OCOrganisationPermissions::generatePermissions
|
||||||
|
@ -0,0 +1,209 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities\Controller;
|
||||||
|
|
||||||
|
use Drupal\Component\Utility\Xss;
|
||||||
|
use Drupal\Core\Controller\ControllerBase;
|
||||||
|
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||||
|
use Drupal\Core\Url;
|
||||||
|
use Drupal\opencase_entities\Entity\OCOrganisationInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class OCOrganisationController.
|
||||||
|
*
|
||||||
|
* Returns responses for Organisation routes.
|
||||||
|
*/
|
||||||
|
class OCOrganisationController extends ControllerBase implements ContainerInjectionInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The date formatter.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Datetime\DateFormatter
|
||||||
|
*/
|
||||||
|
protected $dateFormatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The renderer.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Render\Renderer
|
||||||
|
*/
|
||||||
|
protected $renderer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function create(ContainerInterface $container) {
|
||||||
|
$instance = parent::create($container);
|
||||||
|
$instance->dateFormatter = $container->get('date.formatter');
|
||||||
|
$instance->renderer = $container->get('renderer');
|
||||||
|
return $instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays a Organisation revision.
|
||||||
|
*
|
||||||
|
* @param int $oc_organisation_revision
|
||||||
|
* The Organisation revision ID.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* An array suitable for drupal_render().
|
||||||
|
*/
|
||||||
|
public function revisionShow($oc_organisation_revision) {
|
||||||
|
$oc_organisation = $this->entityTypeManager()->getStorage('oc_organisation')
|
||||||
|
->loadRevision($oc_organisation_revision);
|
||||||
|
$view_builder = $this->entityTypeManager()->getViewBuilder('oc_organisation');
|
||||||
|
|
||||||
|
return $view_builder->view($oc_organisation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page title callback for a Organisation revision.
|
||||||
|
*
|
||||||
|
* @param int $oc_organisation_revision
|
||||||
|
* The Organisation revision ID.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* The page title.
|
||||||
|
*/
|
||||||
|
public function revisionPageTitle($oc_organisation_revision) {
|
||||||
|
$oc_organisation = $this->entityTypeManager()->getStorage('oc_organisation')
|
||||||
|
->loadRevision($oc_organisation_revision);
|
||||||
|
return $this->t('Revision of %title from %date', [
|
||||||
|
'%title' => $oc_organisation->label(),
|
||||||
|
'%date' => $this->dateFormatter->format($oc_organisation->getRevisionCreationTime()),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates an overview table of older revisions of a Organisation.
|
||||||
|
*
|
||||||
|
* @param \Drupal\opencase_entities\Entity\OCOrganisationInterface $oc_organisation
|
||||||
|
* A Organisation object.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* An array as expected by drupal_render().
|
||||||
|
*/
|
||||||
|
public function revisionOverview(OCOrganisationInterface $oc_organisation) {
|
||||||
|
$account = $this->currentUser();
|
||||||
|
$oc_organisation_storage = $this->entityTypeManager()->getStorage('oc_organisation');
|
||||||
|
|
||||||
|
$langcode = $oc_organisation->language()->getId();
|
||||||
|
$langname = $oc_organisation->language()->getName();
|
||||||
|
$languages = $oc_organisation->getTranslationLanguages();
|
||||||
|
$has_translations = (count($languages) > 1);
|
||||||
|
$build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => $oc_organisation->label()]) : $this->t('Revisions for %title', ['%title' => $oc_organisation->label()]);
|
||||||
|
|
||||||
|
$header = [$this->t('Revision'), $this->t('Operations')];
|
||||||
|
$revert_permission = (($account->hasPermission("revert all organisation revisions") || $account->hasPermission('administer organisation entities')));
|
||||||
|
$delete_permission = (($account->hasPermission("delete all organisation revisions") || $account->hasPermission('administer organisation entities')));
|
||||||
|
|
||||||
|
$rows = [];
|
||||||
|
|
||||||
|
$vids = $oc_organisation_storage->revisionIds($oc_organisation);
|
||||||
|
|
||||||
|
$latest_revision = TRUE;
|
||||||
|
|
||||||
|
foreach (array_reverse($vids) as $vid) {
|
||||||
|
/** @var \Drupal\opencase_entities\OCOrganisationInterface $revision */
|
||||||
|
$revision = $oc_organisation_storage->loadRevision($vid);
|
||||||
|
// Only show revisions that are affected by the language that is being
|
||||||
|
// displayed.
|
||||||
|
if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) {
|
||||||
|
$username = [
|
||||||
|
'#theme' => 'username',
|
||||||
|
'#account' => $revision->getRevisionUser(),
|
||||||
|
];
|
||||||
|
|
||||||
|
// Use revision link to link to revisions that are not active.
|
||||||
|
$date = $this->dateFormatter->format($revision->getRevisionCreationTime(), 'short');
|
||||||
|
if ($vid != $oc_organisation->getRevisionId()) {
|
||||||
|
$link = $this->l($date, new Url('entity.oc_organisation.revision', [
|
||||||
|
'oc_organisation' => $oc_organisation->id(),
|
||||||
|
'oc_organisation_revision' => $vid,
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$link = $oc_organisation->link($date);
|
||||||
|
}
|
||||||
|
|
||||||
|
$row = [];
|
||||||
|
$column = [
|
||||||
|
'data' => [
|
||||||
|
'#type' => 'inline_template',
|
||||||
|
'#template' => '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}',
|
||||||
|
'#context' => [
|
||||||
|
'date' => $link,
|
||||||
|
'username' => $this->renderer->renderPlain($username),
|
||||||
|
'message' => [
|
||||||
|
'#markup' => $revision->getRevisionLogMessage(),
|
||||||
|
'#allowed_tags' => Xss::getHtmlTagList(),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$row[] = $column;
|
||||||
|
|
||||||
|
if ($latest_revision) {
|
||||||
|
$row[] = [
|
||||||
|
'data' => [
|
||||||
|
'#prefix' => '<em>',
|
||||||
|
'#markup' => $this->t('Current revision'),
|
||||||
|
'#suffix' => '</em>',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
foreach ($row as &$current) {
|
||||||
|
$current['class'] = ['revision-current'];
|
||||||
|
}
|
||||||
|
$latest_revision = FALSE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$links = [];
|
||||||
|
if ($revert_permission) {
|
||||||
|
$links['revert'] = [
|
||||||
|
'title' => $this->t('Revert'),
|
||||||
|
'url' => $has_translations ?
|
||||||
|
Url::fromRoute('entity.oc_organisation.translation_revert', [
|
||||||
|
'oc_organisation' => $oc_organisation->id(),
|
||||||
|
'oc_organisation_revision' => $vid,
|
||||||
|
'langcode' => $langcode,
|
||||||
|
]) :
|
||||||
|
Url::fromRoute('entity.oc_organisation.revision_revert', [
|
||||||
|
'oc_organisation' => $oc_organisation->id(),
|
||||||
|
'oc_organisation_revision' => $vid,
|
||||||
|
]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($delete_permission) {
|
||||||
|
$links['delete'] = [
|
||||||
|
'title' => $this->t('Delete'),
|
||||||
|
'url' => Url::fromRoute('entity.oc_organisation.revision_delete', [
|
||||||
|
'oc_organisation' => $oc_organisation->id(),
|
||||||
|
'oc_organisation_revision' => $vid,
|
||||||
|
]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$row[] = [
|
||||||
|
'data' => [
|
||||||
|
'#type' => 'operations',
|
||||||
|
'#links' => $links,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$build['oc_organisation_revisions_table'] = [
|
||||||
|
'#theme' => 'table',
|
||||||
|
'#rows' => $rows,
|
||||||
|
'#header' => $header,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $build;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
268
modules/opencase_entities/src/Entity/OCOrganisation.php
Normal file
268
modules/opencase_entities/src/Entity/OCOrganisation.php
Normal file
@ -0,0 +1,268 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities\Entity;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\EntityStorageInterface;
|
||||||
|
use Drupal\Core\Field\BaseFieldDefinition;
|
||||||
|
use Drupal\Core\Entity\EditorialContentEntityBase;
|
||||||
|
use Drupal\Core\Entity\RevisionableInterface;
|
||||||
|
use Drupal\Core\Entity\EntityChangedTrait;
|
||||||
|
use Drupal\Core\Entity\EntityPublishedTrait;
|
||||||
|
use Drupal\Core\Entity\EntityTypeInterface;
|
||||||
|
use Drupal\user\UserInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the Organisation entity.
|
||||||
|
*
|
||||||
|
* @ingroup opencase_entities
|
||||||
|
*
|
||||||
|
* @ContentEntityType(
|
||||||
|
* id = "oc_organisation",
|
||||||
|
* label = @Translation("Organisation"),
|
||||||
|
* bundle_label = @Translation("Organisation type"),
|
||||||
|
* handlers = {
|
||||||
|
* "storage" = "Drupal\opencase_entities\OCOrganisationStorage",
|
||||||
|
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||||
|
* "list_builder" = "Drupal\opencase_entities\OCOrganisationListBuilder",
|
||||||
|
* "views_data" = "Drupal\opencase_entities\Entity\OCOrganisationViewsData",
|
||||||
|
* "translation" = "Drupal\opencase_entities\OCOrganisationTranslationHandler",
|
||||||
|
*
|
||||||
|
* "form" = {
|
||||||
|
* "default" = "Drupal\opencase_entities\Form\OCOrganisationForm",
|
||||||
|
* "add" = "Drupal\opencase_entities\Form\OCOrganisationForm",
|
||||||
|
* "edit" = "Drupal\opencase_entities\Form\OCOrganisationForm",
|
||||||
|
* "delete" = "Drupal\opencase_entities\Form\OCOrganisationDeleteForm",
|
||||||
|
* },
|
||||||
|
* "route_provider" = {
|
||||||
|
* "html" = "Drupal\opencase_entities\OCOrganisationHtmlRouteProvider",
|
||||||
|
* },
|
||||||
|
* "access" = "Drupal\opencase_entities\OCOrganisationAccessControlHandler",
|
||||||
|
* },
|
||||||
|
* base_table = "oc_organisation",
|
||||||
|
* data_table = "oc_organisation_field_data",
|
||||||
|
* revision_table = "oc_organisation_revision",
|
||||||
|
* revision_data_table = "oc_organisation_field_revision",
|
||||||
|
* translatable = TRUE,
|
||||||
|
* permission_granularity = "bundle",
|
||||||
|
* admin_permission = "administer organisation entities",
|
||||||
|
* entity_keys = {
|
||||||
|
* "id" = "id",
|
||||||
|
* "revision" = "vid",
|
||||||
|
* "bundle" = "type",
|
||||||
|
* "label" = "name",
|
||||||
|
* "uuid" = "uuid",
|
||||||
|
* "uid" = "user_id",
|
||||||
|
* "langcode" = "langcode",
|
||||||
|
* "published" = "status",
|
||||||
|
* },
|
||||||
|
* links = {
|
||||||
|
* "canonical" = "/opencase//oc_organisation/{oc_organisation}",
|
||||||
|
* "add-page" = "/opencase//oc_organisation/add",
|
||||||
|
* "add-form" = "/opencase//oc_organisation/add/{oc_organisation_type}",
|
||||||
|
* "edit-form" = "/opencase//oc_organisation/{oc_organisation}/edit",
|
||||||
|
* "delete-form" = "/opencase//oc_organisation/{oc_organisation}/delete",
|
||||||
|
* "version-history" = "/opencase//oc_organisation/{oc_organisation}/revisions",
|
||||||
|
* "revision" = "/opencase//oc_organisation/{oc_organisation}/revisions/{oc_organisation_revision}/view",
|
||||||
|
* "revision_revert" = "/opencase//oc_organisation/{oc_organisation}/revisions/{oc_organisation_revision}/revert",
|
||||||
|
* "revision_delete" = "/opencase//oc_organisation/{oc_organisation}/revisions/{oc_organisation_revision}/delete",
|
||||||
|
* "translation_revert" = "/opencase//oc_organisation/{oc_organisation}/revisions/{oc_organisation_revision}/revert/{langcode}",
|
||||||
|
* "collection" = "/opencase//oc_organisation",
|
||||||
|
* },
|
||||||
|
* bundle_entity_type = "oc_organisation_type",
|
||||||
|
* field_ui_base_route = "entity.oc_organisation_type.edit_form"
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
class OCOrganisation extends EditorialContentEntityBase implements OCOrganisationInterface {
|
||||||
|
|
||||||
|
use EntityChangedTrait;
|
||||||
|
use EntityPublishedTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
|
||||||
|
parent::preCreate($storage_controller, $values);
|
||||||
|
$values += [
|
||||||
|
'user_id' => \Drupal::currentUser()->id(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function urlRouteParameters($rel) {
|
||||||
|
$uri_route_parameters = parent::urlRouteParameters($rel);
|
||||||
|
|
||||||
|
if ($rel === 'revision_revert' && $this instanceof RevisionableInterface) {
|
||||||
|
$uri_route_parameters[$this->getEntityTypeId() . '_revision'] = $this->getRevisionId();
|
||||||
|
}
|
||||||
|
elseif ($rel === 'revision_delete' && $this instanceof RevisionableInterface) {
|
||||||
|
$uri_route_parameters[$this->getEntityTypeId() . '_revision'] = $this->getRevisionId();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $uri_route_parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function preSave(EntityStorageInterface $storage) {
|
||||||
|
parent::preSave($storage);
|
||||||
|
|
||||||
|
foreach (array_keys($this->getTranslationLanguages()) as $langcode) {
|
||||||
|
$translation = $this->getTranslation($langcode);
|
||||||
|
|
||||||
|
// If no owner has been set explicitly, make the anonymous user the owner.
|
||||||
|
if (!$translation->getOwner()) {
|
||||||
|
$translation->setOwnerId(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no revision author has been set explicitly,
|
||||||
|
// make the oc_organisation owner the revision author.
|
||||||
|
if (!$this->getRevisionUser()) {
|
||||||
|
$this->setRevisionUserId($this->getOwnerId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getName() {
|
||||||
|
return $this->get('name')->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setName($name) {
|
||||||
|
$this->set('name', $name);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getCreatedTime() {
|
||||||
|
return $this->get('created')->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setCreatedTime($timestamp) {
|
||||||
|
$this->set('created', $timestamp);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getOwner() {
|
||||||
|
return $this->get('user_id')->entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getOwnerId() {
|
||||||
|
return $this->get('user_id')->target_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setOwnerId($uid) {
|
||||||
|
$this->set('user_id', $uid);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setOwner(UserInterface $account) {
|
||||||
|
$this->set('user_id', $account->id());
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||||
|
$fields = parent::baseFieldDefinitions($entity_type);
|
||||||
|
|
||||||
|
// Add the published field.
|
||||||
|
$fields += static::publishedBaseFieldDefinitions($entity_type);
|
||||||
|
|
||||||
|
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
|
||||||
|
->setLabel(t('Authored by'))
|
||||||
|
->setDescription(t('The user ID of author of the Organisation entity.'))
|
||||||
|
->setRevisionable(TRUE)
|
||||||
|
->setSetting('target_type', 'user')
|
||||||
|
->setSetting('handler', 'default')
|
||||||
|
->setTranslatable(TRUE)
|
||||||
|
->setDisplayOptions('view', [
|
||||||
|
'label' => 'hidden',
|
||||||
|
'type' => 'author',
|
||||||
|
'weight' => 0,
|
||||||
|
])
|
||||||
|
->setDisplayOptions('form', [
|
||||||
|
'type' => 'entity_reference_autocomplete',
|
||||||
|
'weight' => 5,
|
||||||
|
'settings' => [
|
||||||
|
'match_operator' => 'CONTAINS',
|
||||||
|
'size' => '60',
|
||||||
|
'autocomplete_type' => 'tags',
|
||||||
|
'placeholder' => '',
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->setDisplayConfigurable('form', TRUE)
|
||||||
|
->setDisplayConfigurable('view', TRUE);
|
||||||
|
|
||||||
|
$fields['name'] = BaseFieldDefinition::create('string')
|
||||||
|
->setLabel(t('Name'))
|
||||||
|
->setDescription(t('The name of the Organisation entity.'))
|
||||||
|
->setRevisionable(TRUE)
|
||||||
|
->setSettings([
|
||||||
|
'max_length' => 50,
|
||||||
|
'text_processing' => 0,
|
||||||
|
])
|
||||||
|
->setDefaultValue('')
|
||||||
|
->setDisplayOptions('view', [
|
||||||
|
'label' => 'above',
|
||||||
|
'type' => 'string',
|
||||||
|
'weight' => -4,
|
||||||
|
])
|
||||||
|
->setDisplayOptions('form', [
|
||||||
|
'type' => 'string_textfield',
|
||||||
|
'weight' => -4,
|
||||||
|
])
|
||||||
|
->setDisplayConfigurable('form', TRUE)
|
||||||
|
->setDisplayConfigurable('view', TRUE)
|
||||||
|
->setRequired(TRUE);
|
||||||
|
|
||||||
|
$fields['status']->setDescription(t('A boolean indicating whether the Organisation is published.'))
|
||||||
|
->setDisplayOptions('form', [
|
||||||
|
'type' => 'boolean_checkbox',
|
||||||
|
'weight' => -3,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$fields['created'] = BaseFieldDefinition::create('created')
|
||||||
|
->setLabel(t('Created'))
|
||||||
|
->setDescription(t('The time that the entity was created.'));
|
||||||
|
|
||||||
|
$fields['changed'] = BaseFieldDefinition::create('changed')
|
||||||
|
->setLabel(t('Changed'))
|
||||||
|
->setDescription(t('The time that the entity was last edited.'));
|
||||||
|
|
||||||
|
$fields['revision_translation_affected'] = BaseFieldDefinition::create('boolean')
|
||||||
|
->setLabel(t('Revision translation affected'))
|
||||||
|
->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))
|
||||||
|
->setReadOnly(TRUE)
|
||||||
|
->setRevisionable(TRUE)
|
||||||
|
->setTranslatable(TRUE);
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities\Entity;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\ContentEntityInterface;
|
||||||
|
use Drupal\Core\Entity\RevisionLogInterface;
|
||||||
|
use Drupal\Core\Entity\EntityChangedInterface;
|
||||||
|
use Drupal\Core\Entity\EntityPublishedInterface;
|
||||||
|
use Drupal\user\EntityOwnerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an interface for defining Organisation entities.
|
||||||
|
*
|
||||||
|
* @ingroup opencase_entities
|
||||||
|
*/
|
||||||
|
interface OCOrganisationInterface extends ContentEntityInterface, RevisionLogInterface, EntityChangedInterface, EntityPublishedInterface, EntityOwnerInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add get/set methods for your configuration properties here.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Organisation name.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* Name of the Organisation.
|
||||||
|
*/
|
||||||
|
public function getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Organisation name.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* The Organisation name.
|
||||||
|
*
|
||||||
|
* @return \Drupal\opencase_entities\Entity\OCOrganisationInterface
|
||||||
|
* The called Organisation entity.
|
||||||
|
*/
|
||||||
|
public function setName($name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Organisation creation timestamp.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
* Creation timestamp of the Organisation.
|
||||||
|
*/
|
||||||
|
public function getCreatedTime();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Organisation creation timestamp.
|
||||||
|
*
|
||||||
|
* @param int $timestamp
|
||||||
|
* The Organisation creation timestamp.
|
||||||
|
*
|
||||||
|
* @return \Drupal\opencase_entities\Entity\OCOrganisationInterface
|
||||||
|
* The called Organisation entity.
|
||||||
|
*/
|
||||||
|
public function setCreatedTime($timestamp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Organisation revision creation timestamp.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
* The UNIX timestamp of when this revision was created.
|
||||||
|
*/
|
||||||
|
public function getRevisionCreationTime();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Organisation revision creation timestamp.
|
||||||
|
*
|
||||||
|
* @param int $timestamp
|
||||||
|
* The UNIX timestamp of when this revision was created.
|
||||||
|
*
|
||||||
|
* @return \Drupal\opencase_entities\Entity\OCOrganisationInterface
|
||||||
|
* The called Organisation entity.
|
||||||
|
*/
|
||||||
|
public function setRevisionCreationTime($timestamp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Organisation revision author.
|
||||||
|
*
|
||||||
|
* @return \Drupal\user\UserInterface
|
||||||
|
* The user entity for the revision author.
|
||||||
|
*/
|
||||||
|
public function getRevisionUser();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Organisation revision author.
|
||||||
|
*
|
||||||
|
* @param int $uid
|
||||||
|
* The user ID of the revision author.
|
||||||
|
*
|
||||||
|
* @return \Drupal\opencase_entities\Entity\OCOrganisationInterface
|
||||||
|
* The called Organisation entity.
|
||||||
|
*/
|
||||||
|
public function setRevisionUserId($uid);
|
||||||
|
|
||||||
|
}
|
58
modules/opencase_entities/src/Entity/OCOrganisationType.php
Normal file
58
modules/opencase_entities/src/Entity/OCOrganisationType.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities\Entity;
|
||||||
|
|
||||||
|
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the Organisation type entity.
|
||||||
|
*
|
||||||
|
* @ConfigEntityType(
|
||||||
|
* id = "oc_organisation_type",
|
||||||
|
* label = @Translation("Organisation type"),
|
||||||
|
* handlers = {
|
||||||
|
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||||
|
* "list_builder" = "Drupal\opencase_entities\OCOrganisationTypeListBuilder",
|
||||||
|
* "form" = {
|
||||||
|
* "add" = "Drupal\opencase_entities\Form\OCOrganisationTypeForm",
|
||||||
|
* "edit" = "Drupal\opencase_entities\Form\OCOrganisationTypeForm",
|
||||||
|
* "delete" = "Drupal\opencase_entities\Form\OCOrganisationTypeDeleteForm"
|
||||||
|
* },
|
||||||
|
* "route_provider" = {
|
||||||
|
* "html" = "Drupal\opencase_entities\OCOrganisationTypeHtmlRouteProvider",
|
||||||
|
* },
|
||||||
|
* },
|
||||||
|
* config_prefix = "oc_organisation_type",
|
||||||
|
* admin_permission = "administer site configuration",
|
||||||
|
* bundle_of = "oc_organisation",
|
||||||
|
* entity_keys = {
|
||||||
|
* "id" = "id",
|
||||||
|
* "label" = "label",
|
||||||
|
* "uuid" = "uuid"
|
||||||
|
* },
|
||||||
|
* links = {
|
||||||
|
* "canonical" = "/opencase/oc_organisation_type/{oc_organisation_type}",
|
||||||
|
* "add-form" = "/opencase/oc_organisation_type/add",
|
||||||
|
* "edit-form" = "/opencase/oc_organisation_type/{oc_organisation_type}/edit",
|
||||||
|
* "delete-form" = "/opencase/oc_organisation_type/{oc_organisation_type}/delete",
|
||||||
|
* "collection" = "/opencase/oc_organisation_type"
|
||||||
|
* }
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
class OCOrganisationType extends ConfigEntityBundleBase implements OCOrganisationTypeInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Organisation type ID.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Organisation type label.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $label;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities\Entity;
|
||||||
|
|
||||||
|
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an interface for defining Organisation type entities.
|
||||||
|
*/
|
||||||
|
interface OCOrganisationTypeInterface extends ConfigEntityInterface {
|
||||||
|
|
||||||
|
// Add get/set methods for your configuration properties here.
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities\Entity;
|
||||||
|
|
||||||
|
use Drupal\views\EntityViewsData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides Views data for Organisation entities.
|
||||||
|
*/
|
||||||
|
class OCOrganisationViewsData extends EntityViewsData {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getViewsData() {
|
||||||
|
$data = parent::getViewsData();
|
||||||
|
|
||||||
|
// Additional information for Views integration, such as table joins, can be
|
||||||
|
// put here.
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities\Form;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\ContentEntityDeleteForm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a form for deleting Organisation entities.
|
||||||
|
*
|
||||||
|
* @ingroup opencase_entities
|
||||||
|
*/
|
||||||
|
class OCOrganisationDeleteForm extends ContentEntityDeleteForm {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
87
modules/opencase_entities/src/Form/OCOrganisationForm.php
Normal file
87
modules/opencase_entities/src/Form/OCOrganisationForm.php
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities\Form;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\ContentEntityForm;
|
||||||
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form controller for Organisation edit forms.
|
||||||
|
*
|
||||||
|
* @ingroup opencase_entities
|
||||||
|
*/
|
||||||
|
class OCOrganisationForm extends ContentEntityForm {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current user account.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Session\AccountProxyInterface
|
||||||
|
*/
|
||||||
|
protected $account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function create(ContainerInterface $container) {
|
||||||
|
// Instantiates this form class.
|
||||||
|
$instance = parent::create($container);
|
||||||
|
$instance->account = $container->get('current_user');
|
||||||
|
return $instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||||
|
/* @var \Drupal\opencase_entities\Entity\OCOrganisation $entity */
|
||||||
|
$form = parent::buildForm($form, $form_state);
|
||||||
|
|
||||||
|
if (!$this->entity->isNew()) {
|
||||||
|
$form['new_revision'] = [
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => $this->t('Create new revision'),
|
||||||
|
'#default_value' => FALSE,
|
||||||
|
'#weight' => 10,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function save(array $form, FormStateInterface $form_state) {
|
||||||
|
$entity = $this->entity;
|
||||||
|
|
||||||
|
// Save as a new revision if requested to do so.
|
||||||
|
if (!$form_state->isValueEmpty('new_revision') && $form_state->getValue('new_revision') != FALSE) {
|
||||||
|
$entity->setNewRevision();
|
||||||
|
|
||||||
|
// If a new revision is created, save the current user as revision author.
|
||||||
|
$entity->setRevisionCreationTime($this->time->getRequestTime());
|
||||||
|
$entity->setRevisionUserId($this->account->id());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$entity->setNewRevision(FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
$status = parent::save($form, $form_state);
|
||||||
|
|
||||||
|
switch ($status) {
|
||||||
|
case SAVED_NEW:
|
||||||
|
$this->messenger()->addMessage($this->t('Created the %label Organisation.', [
|
||||||
|
'%label' => $entity->label(),
|
||||||
|
]));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
$this->messenger()->addMessage($this->t('Saved the %label Organisation.', [
|
||||||
|
'%label' => $entity->label(),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
$form_state->setRedirect('entity.oc_organisation.canonical', ['oc_organisation' => $entity->id()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities\Form;
|
||||||
|
|
||||||
|
use Drupal\Core\Form\ConfirmFormBase;
|
||||||
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
use Drupal\Core\Url;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a form for deleting a Organisation revision.
|
||||||
|
*
|
||||||
|
* @ingroup opencase_entities
|
||||||
|
*/
|
||||||
|
class OCOrganisationRevisionDeleteForm extends ConfirmFormBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Organisation revision.
|
||||||
|
*
|
||||||
|
* @var \Drupal\opencase_entities\Entity\OCOrganisationInterface
|
||||||
|
*/
|
||||||
|
protected $revision;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Organisation storage.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||||
|
*/
|
||||||
|
protected $oCOrganisationStorage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The database connection.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Database\Connection
|
||||||
|
*/
|
||||||
|
protected $connection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function create(ContainerInterface $container) {
|
||||||
|
$instance = parent::create($container);
|
||||||
|
$instance->oCOrganisationStorage = $container->get('entity_type.manager')->getStorage('oc_organisation');
|
||||||
|
$instance->connection = $container->get('database');
|
||||||
|
return $instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getFormId() {
|
||||||
|
return 'oc_organisation_revision_delete_confirm';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getQuestion() {
|
||||||
|
return $this->t('Are you sure you want to delete the revision from %revision-date?', [
|
||||||
|
'%revision-date' => format_date($this->revision->getRevisionCreationTime()),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getCancelUrl() {
|
||||||
|
return new Url('entity.oc_organisation.version_history', ['oc_organisation' => $this->revision->id()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getConfirmText() {
|
||||||
|
return $this->t('Delete');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function buildForm(array $form, FormStateInterface $form_state, $oc_organisation_revision = NULL) {
|
||||||
|
$this->revision = $this->OCOrganisationStorage->loadRevision($oc_organisation_revision);
|
||||||
|
$form = parent::buildForm($form, $form_state);
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||||
|
$this->OCOrganisationStorage->deleteRevision($this->revision->getRevisionId());
|
||||||
|
|
||||||
|
$this->logger('content')->notice('Organisation: deleted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
|
||||||
|
$this->messenger()->addMessage(t('Revision from %revision-date of Organisation %title has been deleted.', ['%revision-date' => format_date($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()]));
|
||||||
|
$form_state->setRedirect(
|
||||||
|
'entity.oc_organisation.canonical',
|
||||||
|
['oc_organisation' => $this->revision->id()]
|
||||||
|
);
|
||||||
|
if ($this->connection->query('SELECT COUNT(DISTINCT vid) FROM {oc_organisation_field_revision} WHERE id = :id', [':id' => $this->revision->id()])->fetchField() > 1) {
|
||||||
|
$form_state->setRedirect(
|
||||||
|
'entity.oc_organisation.version_history',
|
||||||
|
['oc_organisation' => $this->revision->id()]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,137 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities\Form;
|
||||||
|
|
||||||
|
use Drupal\Core\Form\ConfirmFormBase;
|
||||||
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
use Drupal\Core\Url;
|
||||||
|
use Drupal\opencase_entities\Entity\OCOrganisationInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a form for reverting a Organisation revision.
|
||||||
|
*
|
||||||
|
* @ingroup opencase_entities
|
||||||
|
*/
|
||||||
|
class OCOrganisationRevisionRevertForm extends ConfirmFormBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Organisation revision.
|
||||||
|
*
|
||||||
|
* @var \Drupal\opencase_entities\Entity\OCOrganisationInterface
|
||||||
|
*/
|
||||||
|
protected $revision;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Organisation storage.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||||
|
*/
|
||||||
|
protected $oCOrganisationStorage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The date formatter service.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Datetime\DateFormatterInterface
|
||||||
|
*/
|
||||||
|
protected $dateFormatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function create(ContainerInterface $container) {
|
||||||
|
$instance = parent::create($container);
|
||||||
|
$instance->oCOrganisationStorage = $container->get('entity_type.manager')->getStorage('oc_organisation');
|
||||||
|
$instance->dateFormatter = $container->get('date.formatter');
|
||||||
|
return $instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getFormId() {
|
||||||
|
return 'oc_organisation_revision_revert_confirm';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getQuestion() {
|
||||||
|
return $this->t('Are you sure you want to revert to the revision from %revision-date?', [
|
||||||
|
'%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime()),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getCancelUrl() {
|
||||||
|
return new Url('entity.oc_organisation.version_history', ['oc_organisation' => $this->revision->id()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getConfirmText() {
|
||||||
|
return $this->t('Revert');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getDescription() {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function buildForm(array $form, FormStateInterface $form_state, $oc_organisation_revision = NULL) {
|
||||||
|
$this->revision = $this->OCOrganisationStorage->loadRevision($oc_organisation_revision);
|
||||||
|
$form = parent::buildForm($form, $form_state);
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||||
|
// The revision timestamp will be updated when the revision is saved. Keep
|
||||||
|
// the original one for the confirmation message.
|
||||||
|
$original_revision_timestamp = $this->revision->getRevisionCreationTime();
|
||||||
|
|
||||||
|
$this->revision = $this->prepareRevertedRevision($this->revision, $form_state);
|
||||||
|
$this->revision->revision_log = $this->t('Copy of the revision from %date.', [
|
||||||
|
'%date' => $this->dateFormatter->format($original_revision_timestamp),
|
||||||
|
]);
|
||||||
|
$this->revision->save();
|
||||||
|
|
||||||
|
$this->logger('content')->notice('Organisation: reverted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
|
||||||
|
$this->messenger()->addMessage(t('Organisation %title has been reverted to the revision from %revision-date.', ['%title' => $this->revision->label(), '%revision-date' => $this->dateFormatter->format($original_revision_timestamp)]));
|
||||||
|
$form_state->setRedirect(
|
||||||
|
'entity.oc_organisation.version_history',
|
||||||
|
['oc_organisation' => $this->revision->id()]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepares a revision to be reverted.
|
||||||
|
*
|
||||||
|
* @param \Drupal\opencase_entities\Entity\OCOrganisationInterface $revision
|
||||||
|
* The revision to be reverted.
|
||||||
|
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||||
|
* The current state of the form.
|
||||||
|
*
|
||||||
|
* @return \Drupal\opencase_entities\Entity\OCOrganisationInterface
|
||||||
|
* The prepared revision ready to be stored.
|
||||||
|
*/
|
||||||
|
protected function prepareRevertedRevision(OCOrganisationInterface $revision, FormStateInterface $form_state) {
|
||||||
|
$revision->setNewRevision();
|
||||||
|
$revision->isDefaultRevision(TRUE);
|
||||||
|
$revision->setRevisionCreationTime(REQUEST_TIME);
|
||||||
|
|
||||||
|
return $revision;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities\Form;
|
||||||
|
|
||||||
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
use Drupal\opencase_entities\Entity\OCOrganisationInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a form for reverting a Organisation revision for a single trans.
|
||||||
|
*
|
||||||
|
* @ingroup opencase_entities
|
||||||
|
*/
|
||||||
|
class OCOrganisationRevisionRevertTranslationForm extends OCOrganisationRevisionRevertForm {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The language to be reverted.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $langcode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The language manager.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||||
|
*/
|
||||||
|
protected $languageManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function create(ContainerInterface $container) {
|
||||||
|
$instance = parent::create($container);
|
||||||
|
$instance->languageManager = $container->get('language_manager');
|
||||||
|
return $instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getFormId() {
|
||||||
|
return 'oc_organisation_revision_revert_translation_confirm';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getQuestion() {
|
||||||
|
return $this->t('Are you sure you want to revert @language translation to the revision from %revision-date?', [
|
||||||
|
'@language' => $this->languageManager->getLanguageName($this->langcode),
|
||||||
|
'%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime()),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function buildForm(array $form, FormStateInterface $form_state, $oc_organisation_revision = NULL, $langcode = NULL) {
|
||||||
|
$this->langcode = $langcode;
|
||||||
|
$form = parent::buildForm($form, $form_state, $oc_organisation_revision);
|
||||||
|
|
||||||
|
$form['revert_untranslated_fields'] = [
|
||||||
|
'#type' => 'checkbox',
|
||||||
|
'#title' => $this->t('Revert content shared among translations'),
|
||||||
|
'#default_value' => FALSE,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function prepareRevertedRevision(OCOrganisationInterface $revision, FormStateInterface $form_state) {
|
||||||
|
$revert_untranslated_fields = $form_state->getValue('revert_untranslated_fields');
|
||||||
|
|
||||||
|
/** @var \Drupal\opencase_entities\Entity\OCOrganisationInterface $default_revision */
|
||||||
|
$latest_revision = $this->OCOrganisationStorage->load($revision->id());
|
||||||
|
$latest_revision_translation = $latest_revision->getTranslation($this->langcode);
|
||||||
|
|
||||||
|
$revision_translation = $revision->getTranslation($this->langcode);
|
||||||
|
|
||||||
|
foreach ($latest_revision_translation->getFieldDefinitions() as $field_name => $definition) {
|
||||||
|
if ($definition->isTranslatable() || $revert_untranslated_fields) {
|
||||||
|
$latest_revision_translation->set($field_name, $revision_translation->get($field_name)->getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$latest_revision_translation->setNewRevision();
|
||||||
|
$latest_revision_translation->isDefaultRevision(TRUE);
|
||||||
|
$revision->setRevisionCreationTime(REQUEST_TIME);
|
||||||
|
|
||||||
|
return $latest_revision_translation;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities\Form;
|
||||||
|
|
||||||
|
use Drupal\Core\Form\FormBase;
|
||||||
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class OCOrganisationSettingsForm.
|
||||||
|
*
|
||||||
|
* @ingroup opencase_entities
|
||||||
|
*/
|
||||||
|
class OCOrganisationSettingsForm extends FormBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a unique string identifying the form.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* The unique string identifying the form.
|
||||||
|
*/
|
||||||
|
public function getFormId() {
|
||||||
|
return 'ocorganisation_settings';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form submission handler.
|
||||||
|
*
|
||||||
|
* @param array $form
|
||||||
|
* An associative array containing the structure of the form.
|
||||||
|
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||||
|
* The current state of the form.
|
||||||
|
*/
|
||||||
|
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||||
|
// Empty implementation of the abstract submit class.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the settings form for Organisation entities.
|
||||||
|
*
|
||||||
|
* @param array $form
|
||||||
|
* An associative array containing the structure of the form.
|
||||||
|
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||||
|
* The current state of the form.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* Form definition array.
|
||||||
|
*/
|
||||||
|
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||||
|
$form['ocorganisation_settings']['#markup'] = 'Settings form for Organisation entities. Manage field settings here.';
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities\Form;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\EntityConfirmFormBase;
|
||||||
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
use Drupal\Core\Url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the form to delete Organisation type entities.
|
||||||
|
*/
|
||||||
|
class OCOrganisationTypeDeleteForm extends EntityConfirmFormBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getQuestion() {
|
||||||
|
return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getCancelUrl() {
|
||||||
|
return new Url('entity.oc_organisation_type.collection');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getConfirmText() {
|
||||||
|
return $this->t('Delete');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||||
|
$this->entity->delete();
|
||||||
|
|
||||||
|
$this->messenger()->addMessage(
|
||||||
|
$this->t('content @type: deleted @label.', [
|
||||||
|
'@type' => $this->entity->bundle(),
|
||||||
|
'@label' => $this->entity->label(),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities\Form;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\EntityForm;
|
||||||
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class OCOrganisationTypeForm.
|
||||||
|
*/
|
||||||
|
class OCOrganisationTypeForm extends EntityForm {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function form(array $form, FormStateInterface $form_state) {
|
||||||
|
$form = parent::form($form, $form_state);
|
||||||
|
|
||||||
|
$oc_organisation_type = $this->entity;
|
||||||
|
$form['label'] = [
|
||||||
|
'#type' => 'textfield',
|
||||||
|
'#title' => $this->t('Label'),
|
||||||
|
'#maxlength' => 255,
|
||||||
|
'#default_value' => $oc_organisation_type->label(),
|
||||||
|
'#description' => $this->t("Label for the Organisation type."),
|
||||||
|
'#required' => TRUE,
|
||||||
|
];
|
||||||
|
|
||||||
|
$form['id'] = [
|
||||||
|
'#type' => 'machine_name',
|
||||||
|
'#default_value' => $oc_organisation_type->id(),
|
||||||
|
'#machine_name' => [
|
||||||
|
'exists' => '\Drupal\opencase_entities\Entity\OCOrganisationType::load',
|
||||||
|
],
|
||||||
|
'#disabled' => !$oc_organisation_type->isNew(),
|
||||||
|
];
|
||||||
|
|
||||||
|
/* You will need additional form elements for your custom properties. */
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function save(array $form, FormStateInterface $form_state) {
|
||||||
|
$oc_organisation_type = $this->entity;
|
||||||
|
$status = $oc_organisation_type->save();
|
||||||
|
|
||||||
|
switch ($status) {
|
||||||
|
case SAVED_NEW:
|
||||||
|
$this->messenger()->addMessage($this->t('Created the %label Organisation type.', [
|
||||||
|
'%label' => $oc_organisation_type->label(),
|
||||||
|
]));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
$this->messenger()->addMessage($this->t('Saved the %label Organisation type.', [
|
||||||
|
'%label' => $oc_organisation_type->label(),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
$form_state->setRedirectUrl($oc_organisation_type->toUrl('collection'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\EntityAccessControlHandler;
|
||||||
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
|
use Drupal\Core\Session\AccountInterface;
|
||||||
|
use Drupal\Core\Access\AccessResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access controller for the Organisation entity.
|
||||||
|
*
|
||||||
|
* @see \Drupal\opencase_entities\Entity\OCOrganisation.
|
||||||
|
*/
|
||||||
|
class OCOrganisationAccessControlHandler extends EntityAccessControlHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||||
|
/** @var \Drupal\opencase_entities\Entity\OCOrganisationInterface $entity */
|
||||||
|
|
||||||
|
switch ($operation) {
|
||||||
|
|
||||||
|
case 'view':
|
||||||
|
|
||||||
|
if (!$entity->isPublished()) {
|
||||||
|
$permission = $this->checkOwn($entity, 'view unpublished', $account);
|
||||||
|
if (!empty($permission)) {
|
||||||
|
return AccessResult::allowed();
|
||||||
|
}
|
||||||
|
|
||||||
|
return AccessResult::allowedIfHasPermission($account, 'view unpublished organisation entities');
|
||||||
|
}
|
||||||
|
|
||||||
|
$permission = $this->checkOwn($entity, $operation, $account);
|
||||||
|
if (!empty($permission)) {
|
||||||
|
return AccessResult::allowed();
|
||||||
|
}
|
||||||
|
|
||||||
|
return AccessResult::allowedIfHasPermission($account, 'view published organisation entities');
|
||||||
|
|
||||||
|
case 'update':
|
||||||
|
|
||||||
|
$permission = $this->checkOwn($entity, $operation, $account);
|
||||||
|
if (!empty($permission)) {
|
||||||
|
return AccessResult::allowed();
|
||||||
|
}
|
||||||
|
return AccessResult::allowedIfHasPermission($account, 'edit organisation entities');
|
||||||
|
|
||||||
|
case 'delete':
|
||||||
|
|
||||||
|
$permission = $this->checkOwn($entity, $operation, $account);
|
||||||
|
if (!empty($permission)) {
|
||||||
|
return AccessResult::allowed();
|
||||||
|
}
|
||||||
|
return AccessResult::allowedIfHasPermission($account, 'delete organisation entities');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unknown operation, no opinion.
|
||||||
|
return AccessResult::neutral();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
|
||||||
|
return AccessResult::allowedIfHasPermission($account, 'add organisation entities');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for given 'own' permission.
|
||||||
|
*
|
||||||
|
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||||
|
* @param $operation
|
||||||
|
* @param \Drupal\Core\Session\AccountInterface $account
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* The permission string indicating it's allowed.
|
||||||
|
*/
|
||||||
|
protected function checkOwn(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||||
|
$status = $entity->isPublished();
|
||||||
|
$uid = $entity->getOwnerId();
|
||||||
|
|
||||||
|
$is_own = $account->isAuthenticated() && $account->id() == $uid;
|
||||||
|
if (!$is_own) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$bundle = $entity->bundle();
|
||||||
|
|
||||||
|
$ops = [
|
||||||
|
'create' => '%bundle add own %bundle entities',
|
||||||
|
'view unpublished' => '%bundle view own unpublished %bundle entities',
|
||||||
|
'view' => '%bundle view own entities',
|
||||||
|
'update' => '%bundle edit own entities',
|
||||||
|
'delete' => '%bundle delete own entities',
|
||||||
|
];
|
||||||
|
$permission = strtr($ops[$operation], ['%bundle' => $bundle]);
|
||||||
|
|
||||||
|
if ($operation === 'view unpublished') {
|
||||||
|
if (!$status && $account->hasPermission($permission)) {
|
||||||
|
return $permission;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($account->hasPermission($permission)) {
|
||||||
|
return $permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,196 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\EntityTypeInterface;
|
||||||
|
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||||
|
use Symfony\Component\Routing\Route;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides routes for Organisation entities.
|
||||||
|
*
|
||||||
|
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||||
|
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||||
|
*/
|
||||||
|
class OCOrganisationHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getRoutes(EntityTypeInterface $entity_type) {
|
||||||
|
$collection = parent::getRoutes($entity_type);
|
||||||
|
|
||||||
|
$entity_type_id = $entity_type->id();
|
||||||
|
|
||||||
|
if ($history_route = $this->getHistoryRoute($entity_type)) {
|
||||||
|
$collection->add("entity.{$entity_type_id}.version_history", $history_route);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($revision_route = $this->getRevisionRoute($entity_type)) {
|
||||||
|
$collection->add("entity.{$entity_type_id}.revision", $revision_route);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($revert_route = $this->getRevisionRevertRoute($entity_type)) {
|
||||||
|
$collection->add("entity.{$entity_type_id}.revision_revert", $revert_route);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($delete_route = $this->getRevisionDeleteRoute($entity_type)) {
|
||||||
|
$collection->add("entity.{$entity_type_id}.revision_delete", $delete_route);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($translation_route = $this->getRevisionTranslationRevertRoute($entity_type)) {
|
||||||
|
$collection->add("{$entity_type_id}.revision_revert_translation_confirm", $translation_route);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
|
||||||
|
$collection->add("$entity_type_id.settings", $settings_form_route);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the version history route.
|
||||||
|
*
|
||||||
|
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||||
|
* The entity type.
|
||||||
|
*
|
||||||
|
* @return \Symfony\Component\Routing\Route|null
|
||||||
|
* The generated route, if available.
|
||||||
|
*/
|
||||||
|
protected function getHistoryRoute(EntityTypeInterface $entity_type) {
|
||||||
|
if ($entity_type->hasLinkTemplate('version-history')) {
|
||||||
|
$route = new Route($entity_type->getLinkTemplate('version-history'));
|
||||||
|
$route
|
||||||
|
->setDefaults([
|
||||||
|
'_title' => "{$entity_type->getLabel()} revisions",
|
||||||
|
'_controller' => '\Drupal\opencase_entities\Controller\OCOrganisationController::revisionOverview',
|
||||||
|
])
|
||||||
|
->setRequirement('_permission', 'view all organisation revisions')
|
||||||
|
->setOption('_admin_route', TRUE);
|
||||||
|
|
||||||
|
return $route;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the revision route.
|
||||||
|
*
|
||||||
|
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||||
|
* The entity type.
|
||||||
|
*
|
||||||
|
* @return \Symfony\Component\Routing\Route|null
|
||||||
|
* The generated route, if available.
|
||||||
|
*/
|
||||||
|
protected function getRevisionRoute(EntityTypeInterface $entity_type) {
|
||||||
|
if ($entity_type->hasLinkTemplate('revision')) {
|
||||||
|
$route = new Route($entity_type->getLinkTemplate('revision'));
|
||||||
|
$route
|
||||||
|
->setDefaults([
|
||||||
|
'_controller' => '\Drupal\opencase_entities\Controller\OCOrganisationController::revisionShow',
|
||||||
|
'_title_callback' => '\Drupal\opencase_entities\Controller\OCOrganisationController::revisionPageTitle',
|
||||||
|
])
|
||||||
|
->setRequirement('_permission', 'view all organisation revisions')
|
||||||
|
->setOption('_admin_route', TRUE);
|
||||||
|
|
||||||
|
return $route;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the revision revert route.
|
||||||
|
*
|
||||||
|
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||||
|
* The entity type.
|
||||||
|
*
|
||||||
|
* @return \Symfony\Component\Routing\Route|null
|
||||||
|
* The generated route, if available.
|
||||||
|
*/
|
||||||
|
protected function getRevisionRevertRoute(EntityTypeInterface $entity_type) {
|
||||||
|
if ($entity_type->hasLinkTemplate('revision_revert')) {
|
||||||
|
$route = new Route($entity_type->getLinkTemplate('revision_revert'));
|
||||||
|
$route
|
||||||
|
->setDefaults([
|
||||||
|
'_form' => '\Drupal\opencase_entities\Form\OCOrganisationRevisionRevertForm',
|
||||||
|
'_title' => 'Revert to earlier revision',
|
||||||
|
])
|
||||||
|
->setRequirement('_permission', 'revert all organisation revisions')
|
||||||
|
->setOption('_admin_route', TRUE);
|
||||||
|
|
||||||
|
return $route;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the revision delete route.
|
||||||
|
*
|
||||||
|
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||||
|
* The entity type.
|
||||||
|
*
|
||||||
|
* @return \Symfony\Component\Routing\Route|null
|
||||||
|
* The generated route, if available.
|
||||||
|
*/
|
||||||
|
protected function getRevisionDeleteRoute(EntityTypeInterface $entity_type) {
|
||||||
|
if ($entity_type->hasLinkTemplate('revision_delete')) {
|
||||||
|
$route = new Route($entity_type->getLinkTemplate('revision_delete'));
|
||||||
|
$route
|
||||||
|
->setDefaults([
|
||||||
|
'_form' => '\Drupal\opencase_entities\Form\OCOrganisationRevisionDeleteForm',
|
||||||
|
'_title' => 'Delete earlier revision',
|
||||||
|
])
|
||||||
|
->setRequirement('_permission', 'delete all organisation revisions')
|
||||||
|
->setOption('_admin_route', TRUE);
|
||||||
|
|
||||||
|
return $route;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the revision translation revert route.
|
||||||
|
*
|
||||||
|
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||||
|
* The entity type.
|
||||||
|
*
|
||||||
|
* @return \Symfony\Component\Routing\Route|null
|
||||||
|
* The generated route, if available.
|
||||||
|
*/
|
||||||
|
protected function getRevisionTranslationRevertRoute(EntityTypeInterface $entity_type) {
|
||||||
|
if ($entity_type->hasLinkTemplate('translation_revert')) {
|
||||||
|
$route = new Route($entity_type->getLinkTemplate('translation_revert'));
|
||||||
|
$route
|
||||||
|
->setDefaults([
|
||||||
|
'_form' => '\Drupal\opencase_entities\Form\OCOrganisationRevisionRevertTranslationForm',
|
||||||
|
'_title' => 'Revert to earlier revision of a translation',
|
||||||
|
])
|
||||||
|
->setRequirement('_permission', 'revert all organisation revisions')
|
||||||
|
->setOption('_admin_route', TRUE);
|
||||||
|
|
||||||
|
return $route;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the settings form route.
|
||||||
|
*
|
||||||
|
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||||
|
* The entity type.
|
||||||
|
*
|
||||||
|
* @return \Symfony\Component\Routing\Route|null
|
||||||
|
* The generated route, if available.
|
||||||
|
*/
|
||||||
|
protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
|
||||||
|
if (!$entity_type->getBundleEntityType()) {
|
||||||
|
$route = new Route("/admin/structure/{$entity_type->id()}/settings");
|
||||||
|
$route
|
||||||
|
->setDefaults([
|
||||||
|
'_form' => 'Drupal\opencase_entities\Form\OCOrganisationSettingsForm',
|
||||||
|
'_title' => "{$entity_type->getLabel()} settings",
|
||||||
|
])
|
||||||
|
->setRequirement('_permission', $entity_type->getAdminPermission())
|
||||||
|
->setOption('_admin_route', TRUE);
|
||||||
|
|
||||||
|
return $route;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
39
modules/opencase_entities/src/OCOrganisationListBuilder.php
Normal file
39
modules/opencase_entities/src/OCOrganisationListBuilder.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
|
use Drupal\Core\Entity\EntityListBuilder;
|
||||||
|
use Drupal\Core\Link;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines a class to build a listing of Organisation entities.
|
||||||
|
*
|
||||||
|
* @ingroup opencase_entities
|
||||||
|
*/
|
||||||
|
class OCOrganisationListBuilder extends EntityListBuilder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function buildHeader() {
|
||||||
|
$header['id'] = $this->t('Organisation ID');
|
||||||
|
$header['name'] = $this->t('Name');
|
||||||
|
return $header + parent::buildHeader();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function buildRow(EntityInterface $entity) {
|
||||||
|
/* @var \Drupal\opencase_entities\Entity\OCOrganisation $entity */
|
||||||
|
$row['id'] = $entity->id();
|
||||||
|
$row['name'] = Link::createFromRoute(
|
||||||
|
$entity->label(),
|
||||||
|
'entity.oc_organisation.edit_form',
|
||||||
|
['oc_organisation' => $entity->id()]
|
||||||
|
);
|
||||||
|
return $row + parent::buildRow($entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
80
modules/opencase_entities/src/OCOrganisationPermissions.php
Normal file
80
modules/opencase_entities/src/OCOrganisationPermissions.php
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities;
|
||||||
|
|
||||||
|
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||||
|
use Drupal\opencase_entities\Entity\OCOrganisation;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides dynamic permissions for Organisation of different types.
|
||||||
|
*
|
||||||
|
* @ingroup opencase_entities
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class OCOrganisationPermissions{
|
||||||
|
|
||||||
|
use StringTranslationTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of node type permissions.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* The OCOrganisation by bundle permissions.
|
||||||
|
* @see \Drupal\user\PermissionHandlerInterface::getPermissions()
|
||||||
|
*/
|
||||||
|
public function generatePermissions() {
|
||||||
|
$perms = [];
|
||||||
|
|
||||||
|
foreach (OCOrganisation::loadMultiple() as $type) {
|
||||||
|
$perms += $this->buildPermissions($type);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $perms;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of node permissions for a given node type.
|
||||||
|
*
|
||||||
|
* @param \Drupal\opencase_entities\Entity\OCOrganisation $type
|
||||||
|
* The OCOrganisation type.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* An associative array of permission names and descriptions.
|
||||||
|
*/
|
||||||
|
protected function buildPermissions(OCOrganisation $type) {
|
||||||
|
$type_id = $type->id();
|
||||||
|
$type_params = ['%type_name' => $type->label()];
|
||||||
|
|
||||||
|
return [
|
||||||
|
"$type_id create entities" => [
|
||||||
|
'title' => $this->t('Create new %type_name entities', $type_params),
|
||||||
|
],
|
||||||
|
"$type_id edit own entities" => [
|
||||||
|
'title' => $this->t('Edit own %type_name entities', $type_params),
|
||||||
|
],
|
||||||
|
"$type_id edit any entities" => [
|
||||||
|
'title' => $this->t('Edit any %type_name entities', $type_params),
|
||||||
|
],
|
||||||
|
"$type_id delete own entities" => [
|
||||||
|
'title' => $this->t('Delete own %type_name entities', $type_params),
|
||||||
|
],
|
||||||
|
"$type_id delete any entities" => [
|
||||||
|
'title' => $this->t('Delete any %type_name entities', $type_params),
|
||||||
|
],
|
||||||
|
"$type_id view revisions" => [
|
||||||
|
'title' => $this->t('View %type_name revisions', $type_params),
|
||||||
|
'description' => t('To view a revision, you also need permission to view the entity item.'),
|
||||||
|
],
|
||||||
|
"$type_id revert revisions" => [
|
||||||
|
'title' => $this->t('Revert %type_name revisions', $type_params),
|
||||||
|
'description' => t('To revert a revision, you also need permission to edit the entity item.'),
|
||||||
|
],
|
||||||
|
"$type_id delete revisions" => [
|
||||||
|
'title' => $this->t('Delete %type_name revisions', $type_params),
|
||||||
|
'description' => $this->t('To delete a revision, you also need permission to delete the entity item.'),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
58
modules/opencase_entities/src/OCOrganisationStorage.php
Normal file
58
modules/opencase_entities/src/OCOrganisationStorage.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
|
||||||
|
use Drupal\Core\Session\AccountInterface;
|
||||||
|
use Drupal\Core\Language\LanguageInterface;
|
||||||
|
use Drupal\opencase_entities\Entity\OCOrganisationInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the storage handler class for Organisation entities.
|
||||||
|
*
|
||||||
|
* This extends the base storage class, adding required special handling for
|
||||||
|
* Organisation entities.
|
||||||
|
*
|
||||||
|
* @ingroup opencase_entities
|
||||||
|
*/
|
||||||
|
class OCOrganisationStorage extends SqlContentEntityStorage implements OCOrganisationStorageInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function revisionIds(OCOrganisationInterface $entity) {
|
||||||
|
return $this->database->query(
|
||||||
|
'SELECT vid FROM {oc_organisation_revision} WHERE id=:id ORDER BY vid',
|
||||||
|
[':id' => $entity->id()]
|
||||||
|
)->fetchCol();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function userRevisionIds(AccountInterface $account) {
|
||||||
|
return $this->database->query(
|
||||||
|
'SELECT vid FROM {oc_organisation_field_revision} WHERE uid = :uid ORDER BY vid',
|
||||||
|
[':uid' => $account->id()]
|
||||||
|
)->fetchCol();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function countDefaultLanguageRevisions(OCOrganisationInterface $entity) {
|
||||||
|
return $this->database->query('SELECT COUNT(*) FROM {oc_organisation_field_revision} WHERE id = :id AND default_langcode = 1', [':id' => $entity->id()])
|
||||||
|
->fetchField();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function clearRevisionsLanguage(LanguageInterface $language) {
|
||||||
|
return $this->database->update('oc_organisation_revision')
|
||||||
|
->fields(['langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED])
|
||||||
|
->condition('langcode', $language->getId())
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\ContentEntityStorageInterface;
|
||||||
|
use Drupal\Core\Session\AccountInterface;
|
||||||
|
use Drupal\Core\Language\LanguageInterface;
|
||||||
|
use Drupal\opencase_entities\Entity\OCOrganisationInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the storage handler class for Organisation entities.
|
||||||
|
*
|
||||||
|
* This extends the base storage class, adding required special handling for
|
||||||
|
* Organisation entities.
|
||||||
|
*
|
||||||
|
* @ingroup opencase_entities
|
||||||
|
*/
|
||||||
|
interface OCOrganisationStorageInterface extends ContentEntityStorageInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of Organisation revision IDs for a specific Organisation.
|
||||||
|
*
|
||||||
|
* @param \Drupal\opencase_entities\Entity\OCOrganisationInterface $entity
|
||||||
|
* The Organisation entity.
|
||||||
|
*
|
||||||
|
* @return int[]
|
||||||
|
* Organisation revision IDs (in ascending order).
|
||||||
|
*/
|
||||||
|
public function revisionIds(OCOrganisationInterface $entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of revision IDs having a given user as Organisation author.
|
||||||
|
*
|
||||||
|
* @param \Drupal\Core\Session\AccountInterface $account
|
||||||
|
* The user entity.
|
||||||
|
*
|
||||||
|
* @return int[]
|
||||||
|
* Organisation revision IDs (in ascending order).
|
||||||
|
*/
|
||||||
|
public function userRevisionIds(AccountInterface $account);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counts the number of revisions in the default language.
|
||||||
|
*
|
||||||
|
* @param \Drupal\opencase_entities\Entity\OCOrganisationInterface $entity
|
||||||
|
* The Organisation entity.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
* The number of revisions in the default language.
|
||||||
|
*/
|
||||||
|
public function countDefaultLanguageRevisions(OCOrganisationInterface $entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsets the language for all Organisation with the given language.
|
||||||
|
*
|
||||||
|
* @param \Drupal\Core\Language\LanguageInterface $language
|
||||||
|
* The language object.
|
||||||
|
*/
|
||||||
|
public function clearRevisionsLanguage(LanguageInterface $language);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities;
|
||||||
|
|
||||||
|
use Drupal\content_translation\ContentTranslationHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the translation handler for oc_organisation.
|
||||||
|
*/
|
||||||
|
class OCOrganisationTranslationHandler extends ContentTranslationHandler {
|
||||||
|
|
||||||
|
// Override here the needed methods from ContentTranslationHandler.
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\EntityTypeInterface;
|
||||||
|
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides routes for Organisation type entities.
|
||||||
|
*
|
||||||
|
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||||
|
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||||
|
*/
|
||||||
|
class OCOrganisationTypeHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getRoutes(EntityTypeInterface $entity_type) {
|
||||||
|
$collection = parent::getRoutes($entity_type);
|
||||||
|
|
||||||
|
// Provide your custom entity routes here.
|
||||||
|
return $collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\opencase_entities;
|
||||||
|
|
||||||
|
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
|
||||||
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a listing of Organisation type entities.
|
||||||
|
*/
|
||||||
|
class OCOrganisationTypeListBuilder extends ConfigEntityListBuilder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function buildHeader() {
|
||||||
|
$header['label'] = $this->t('Organisation type');
|
||||||
|
$header['id'] = $this->t('Machine name');
|
||||||
|
return $header + parent::buildHeader();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function buildRow(EntityInterface $entity) {
|
||||||
|
$row['label'] = $entity->label();
|
||||||
|
$row['id'] = $entity->id();
|
||||||
|
// You probably want a few more properties here...
|
||||||
|
return $row + parent::buildRow($entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
{#
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Default theme implementation to present a list of custom content entity types/bundles.
|
||||||
|
*
|
||||||
|
* Available variables:
|
||||||
|
* - types: A collection of all the available custom entity types/bundles.
|
||||||
|
* Each type/bundle contains the following:
|
||||||
|
* - link: A link to add a content entity of this type.
|
||||||
|
* - description: A description of this content entity types/bundle.
|
||||||
|
*
|
||||||
|
* @see template_preprocess_oc_organisation_content_add_list()
|
||||||
|
*
|
||||||
|
* @ingroup themeable
|
||||||
|
*/
|
||||||
|
#}
|
||||||
|
{% spaceless %}
|
||||||
|
<dl>
|
||||||
|
{% for type in types %}
|
||||||
|
<dt>{{ type.link }}</dt>
|
||||||
|
{% endfor %}
|
||||||
|
</dl>
|
||||||
|
{% endspaceless %}
|
@ -0,0 +1,22 @@
|
|||||||
|
{#
|
||||||
|
/**
|
||||||
|
* @file oc_organisation.html.twig
|
||||||
|
* Default theme implementation to present Organisation data.
|
||||||
|
*
|
||||||
|
* This template is used when viewing Organisation pages.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Available variables:
|
||||||
|
* - content: A list of content items. Use 'content' to print all content, or
|
||||||
|
* - attributes: HTML attributes for the container element.
|
||||||
|
*
|
||||||
|
* @see template_preprocess_oc_organisation()
|
||||||
|
*
|
||||||
|
* @ingroup themeable
|
||||||
|
*/
|
||||||
|
#}
|
||||||
|
<div{{ attributes.addClass('oc_organisation') }}>
|
||||||
|
{% if content %}
|
||||||
|
{{- content -}}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
Reference in New Issue
Block a user