Made Actor, Activity and Case entities
This commit is contained in:
parent
398a6c71a3
commit
249003bf16
@ -0,0 +1,12 @@
|
||||
opencase_entities.oc_activity_type.*:
|
||||
type: config_entity
|
||||
label: 'Activity type config'
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'ID'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
uuid:
|
||||
type: string
|
@ -0,0 +1,12 @@
|
||||
opencase_entities.oc_actor_type.*:
|
||||
type: config_entity
|
||||
label: 'Actor type config'
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'ID'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
uuid:
|
||||
type: string
|
@ -0,0 +1,12 @@
|
||||
opencase_entities.oc_case_type.*:
|
||||
type: config_entity
|
||||
label: 'Case type config'
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'ID'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
uuid:
|
||||
type: string
|
30
modules/opencase_entities/oc_activity.page.inc
Normal file
30
modules/opencase_entities/oc_activity.page.inc
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains oc_activity.page.inc.
|
||||
*
|
||||
* Page callback for Activity entities.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Render\Element;
|
||||
|
||||
/**
|
||||
* Prepares variables for Activity templates.
|
||||
*
|
||||
* Default template: oc_activity.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_activity(array &$variables) {
|
||||
// Fetch OCActivity Entity Object.
|
||||
$oc_activity = $variables['elements']['#oc_activity'];
|
||||
|
||||
// Helpful $content variable for templates.
|
||||
foreach (Element::children($variables['elements']) as $key) {
|
||||
$variables['content'][$key] = $variables['elements'][$key];
|
||||
}
|
||||
}
|
30
modules/opencase_entities/oc_actor.page.inc
Normal file
30
modules/opencase_entities/oc_actor.page.inc
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains oc_actor.page.inc.
|
||||
*
|
||||
* Page callback for Actor entities.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Render\Element;
|
||||
|
||||
/**
|
||||
* Prepares variables for Actor templates.
|
||||
*
|
||||
* Default template: oc_actor.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_actor(array &$variables) {
|
||||
// Fetch OCActor Entity Object.
|
||||
$oc_actor = $variables['elements']['#oc_actor'];
|
||||
|
||||
// Helpful $content variable for templates.
|
||||
foreach (Element::children($variables['elements']) as $key) {
|
||||
$variables['content'][$key] = $variables['elements'][$key];
|
||||
}
|
||||
}
|
30
modules/opencase_entities/oc_case.page.inc
Normal file
30
modules/opencase_entities/oc_case.page.inc
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains oc_case.page.inc.
|
||||
*
|
||||
* Page callback for Case entities.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Render\Element;
|
||||
|
||||
/**
|
||||
* Prepares variables for Case templates.
|
||||
*
|
||||
* Default template: oc_case.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_case(array &$variables) {
|
||||
// Fetch OCCase Entity Object.
|
||||
$oc_case = $variables['elements']['#oc_case'];
|
||||
|
||||
// Helpful $content variable for templates.
|
||||
foreach (Element::children($variables['elements']) as $key) {
|
||||
$variables['content'][$key] = $variables['elements'][$key];
|
||||
}
|
||||
}
|
33
modules/opencase_entities/opencase_entities.links.action.yml
Normal file
33
modules/opencase_entities/opencase_entities.links.action.yml
Normal file
@ -0,0 +1,33 @@
|
||||
entity.oc_actor.add_form:
|
||||
route_name: entity.oc_actor.add_page
|
||||
title: 'Add Actor'
|
||||
appears_on:
|
||||
- entity.oc_actor.collection
|
||||
entity.oc_actor_type.add_form:
|
||||
route_name: entity.oc_actor_type.add_form
|
||||
title: 'Add Actor type'
|
||||
appears_on:
|
||||
- entity.oc_actor_type.collection
|
||||
|
||||
entity.oc_case.add_form:
|
||||
route_name: entity.oc_case.add_page
|
||||
title: 'Add Case'
|
||||
appears_on:
|
||||
- entity.oc_case.collection
|
||||
entity.oc_case_type.add_form:
|
||||
route_name: entity.oc_case_type.add_form
|
||||
title: 'Add Case type'
|
||||
appears_on:
|
||||
- entity.oc_case_type.collection
|
||||
|
||||
entity.oc_activity.add_form:
|
||||
route_name: entity.oc_activity.add_page
|
||||
title: 'Add Activity'
|
||||
appears_on:
|
||||
- entity.oc_activity.collection
|
||||
entity.oc_activity_type.add_form:
|
||||
route_name: entity.oc_activity_type.add_form
|
||||
title: 'Add Activity type'
|
||||
appears_on:
|
||||
- entity.oc_activity_type.collection
|
||||
|
54
modules/opencase_entities/opencase_entities.links.menu.yml
Normal file
54
modules/opencase_entities/opencase_entities.links.menu.yml
Normal file
@ -0,0 +1,54 @@
|
||||
|
||||
# Actor menu items definition
|
||||
entity.oc_actor.collection:
|
||||
title: 'Actor list'
|
||||
route_name: entity.oc_actor.collection
|
||||
description: 'List Actor entities'
|
||||
parent: system.admin_structure
|
||||
weight: 100
|
||||
|
||||
|
||||
# Actor type menu items definition
|
||||
entity.oc_actor_type.collection:
|
||||
title: 'Actor type'
|
||||
route_name: entity.oc_actor_type.collection
|
||||
description: 'List Actor type (bundles)'
|
||||
parent: system.admin_structure
|
||||
weight: 99
|
||||
|
||||
|
||||
# Case menu items definition
|
||||
entity.oc_case.collection:
|
||||
title: 'Case list'
|
||||
route_name: entity.oc_case.collection
|
||||
description: 'List Case entities'
|
||||
parent: system.admin_structure
|
||||
weight: 100
|
||||
|
||||
|
||||
# Case type menu items definition
|
||||
entity.oc_case_type.collection:
|
||||
title: 'Case type'
|
||||
route_name: entity.oc_case_type.collection
|
||||
description: 'List Case type (bundles)'
|
||||
parent: system.admin_structure
|
||||
weight: 99
|
||||
|
||||
|
||||
# Activity menu items definition
|
||||
entity.oc_activity.collection:
|
||||
title: 'Activity list'
|
||||
route_name: entity.oc_activity.collection
|
||||
description: 'List Activity entities'
|
||||
parent: system.admin_structure
|
||||
weight: 100
|
||||
|
||||
|
||||
# Activity type menu items definition
|
||||
entity.oc_activity_type.collection:
|
||||
title: 'Activity type'
|
||||
route_name: entity.oc_activity_type.collection
|
||||
description: 'List Activity type (bundles)'
|
||||
parent: system.admin_structure
|
||||
weight: 99
|
||||
|
69
modules/opencase_entities/opencase_entities.links.task.yml
Normal file
69
modules/opencase_entities/opencase_entities.links.task.yml
Normal file
@ -0,0 +1,69 @@
|
||||
# Actor routing definition
|
||||
|
||||
entity.oc_actor.canonical:
|
||||
route_name: entity.oc_actor.canonical
|
||||
base_route: entity.oc_actor.canonical
|
||||
title: 'View'
|
||||
|
||||
entity.oc_actor.edit_form:
|
||||
route_name: entity.oc_actor.edit_form
|
||||
base_route: entity.oc_actor.canonical
|
||||
title: 'Edit'
|
||||
|
||||
entity.oc_actor.version_history:
|
||||
route_name: entity.oc_actor.version_history
|
||||
base_route: entity.oc_actor.canonical
|
||||
title: 'Revisions'
|
||||
|
||||
entity.oc_actor.delete_form:
|
||||
route_name: entity.oc_actor.delete_form
|
||||
base_route: entity.oc_actor.canonical
|
||||
title: Delete
|
||||
weight: 10
|
||||
|
||||
# Case routing definition
|
||||
|
||||
entity.oc_case.canonical:
|
||||
route_name: entity.oc_case.canonical
|
||||
base_route: entity.oc_case.canonical
|
||||
title: 'View'
|
||||
|
||||
entity.oc_case.edit_form:
|
||||
route_name: entity.oc_case.edit_form
|
||||
base_route: entity.oc_case.canonical
|
||||
title: 'Edit'
|
||||
|
||||
entity.oc_case.version_history:
|
||||
route_name: entity.oc_case.version_history
|
||||
base_route: entity.oc_case.canonical
|
||||
title: 'Revisions'
|
||||
|
||||
entity.oc_case.delete_form:
|
||||
route_name: entity.oc_case.delete_form
|
||||
base_route: entity.oc_case.canonical
|
||||
title: Delete
|
||||
weight: 10
|
||||
|
||||
# Activity routing definition
|
||||
|
||||
entity.oc_activity.canonical:
|
||||
route_name: entity.oc_activity.canonical
|
||||
base_route: entity.oc_activity.canonical
|
||||
title: 'View'
|
||||
|
||||
entity.oc_activity.edit_form:
|
||||
route_name: entity.oc_activity.edit_form
|
||||
base_route: entity.oc_activity.canonical
|
||||
title: 'Edit'
|
||||
|
||||
entity.oc_activity.version_history:
|
||||
route_name: entity.oc_activity.version_history
|
||||
base_route: entity.oc_activity.canonical
|
||||
title: 'Revisions'
|
||||
|
||||
entity.oc_activity.delete_form:
|
||||
route_name: entity.oc_activity.delete_form
|
||||
base_route: entity.oc_activity.canonical
|
||||
title: Delete
|
||||
weight: 10
|
||||
|
@ -27,9 +27,87 @@ function opencase_entities_help($route_name, RouteMatchInterface $route_match) {
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function opencase_entities_theme() {
|
||||
return [
|
||||
'opencase_entities' => [
|
||||
'render element' => 'children',
|
||||
],
|
||||
$theme = [];
|
||||
$theme['opencase_entities'] = [
|
||||
'render element' => 'children',
|
||||
];
|
||||
$theme['oc_actor'] = [
|
||||
'render element' => 'elements',
|
||||
'file' => 'oc_actor.page.inc',
|
||||
'template' => 'oc_actor',
|
||||
];
|
||||
$theme['oc_actor_content_add_list'] = [
|
||||
'render element' => 'content',
|
||||
'variables' => ['content' => NULL],
|
||||
'file' => 'oc_actor.page.inc',
|
||||
];
|
||||
$theme['oc_case'] = [
|
||||
'render element' => 'elements',
|
||||
'file' => 'oc_case.page.inc',
|
||||
'template' => 'oc_case',
|
||||
];
|
||||
$theme['oc_case_content_add_list'] = [
|
||||
'render element' => 'content',
|
||||
'variables' => ['content' => NULL],
|
||||
'file' => 'oc_case.page.inc',
|
||||
];
|
||||
$theme['oc_activity'] = [
|
||||
'render element' => 'elements',
|
||||
'file' => 'oc_activity.page.inc',
|
||||
'template' => 'oc_activity',
|
||||
];
|
||||
$theme['oc_activity_content_add_list'] = [
|
||||
'render element' => 'content',
|
||||
'variables' => ['content' => NULL],
|
||||
'file' => 'oc_activity.page.inc',
|
||||
];
|
||||
return $theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme_suggestions_HOOK().
|
||||
*/
|
||||
function opencase_entities_theme_suggestions_oc_actor(array $variables) {
|
||||
$suggestions = [];
|
||||
$entity = $variables['elements']['#oc_actor'];
|
||||
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
|
||||
|
||||
$suggestions[] = 'oc_actor__' . $sanitized_view_mode;
|
||||
$suggestions[] = 'oc_actor__' . $entity->bundle();
|
||||
$suggestions[] = 'oc_actor__' . $entity->bundle() . '__' . $sanitized_view_mode;
|
||||
$suggestions[] = 'oc_actor__' . $entity->id();
|
||||
$suggestions[] = 'oc_actor__' . $entity->id() . '__' . $sanitized_view_mode;
|
||||
return $suggestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme_suggestions_HOOK().
|
||||
*/
|
||||
function opencase_entities_theme_suggestions_oc_case(array $variables) {
|
||||
$suggestions = [];
|
||||
$entity = $variables['elements']['#oc_case'];
|
||||
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
|
||||
|
||||
$suggestions[] = 'oc_case__' . $sanitized_view_mode;
|
||||
$suggestions[] = 'oc_case__' . $entity->bundle();
|
||||
$suggestions[] = 'oc_case__' . $entity->bundle() . '__' . $sanitized_view_mode;
|
||||
$suggestions[] = 'oc_case__' . $entity->id();
|
||||
$suggestions[] = 'oc_case__' . $entity->id() . '__' . $sanitized_view_mode;
|
||||
return $suggestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme_suggestions_HOOK().
|
||||
*/
|
||||
function opencase_entities_theme_suggestions_oc_activity(array $variables) {
|
||||
$suggestions = [];
|
||||
$entity = $variables['elements']['#oc_activity'];
|
||||
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
|
||||
|
||||
$suggestions[] = 'oc_activity__' . $sanitized_view_mode;
|
||||
$suggestions[] = 'oc_activity__' . $entity->bundle();
|
||||
$suggestions[] = 'oc_activity__' . $entity->bundle() . '__' . $sanitized_view_mode;
|
||||
$suggestions[] = 'oc_activity__' . $entity->id();
|
||||
$suggestions[] = 'oc_activity__' . $entity->id() . '__' . $sanitized_view_mode;
|
||||
return $suggestions;
|
||||
}
|
||||
|
90
modules/opencase_entities/opencase_entities.permissions.yml
Normal file
90
modules/opencase_entities/opencase_entities.permissions.yml
Normal file
@ -0,0 +1,90 @@
|
||||
add actor entities:
|
||||
title: 'Create new Actor entities'
|
||||
|
||||
administer actor entities:
|
||||
title: 'Administer Actor entities'
|
||||
description: 'Allow to access the administration form to configure Actor entities.'
|
||||
restrict access: true
|
||||
|
||||
delete actor entities:
|
||||
title: 'Delete Actor entities'
|
||||
|
||||
edit actor entities:
|
||||
title: 'Edit Actor entities'
|
||||
|
||||
view published actor entities:
|
||||
title: 'View published Actor entities'
|
||||
|
||||
view unpublished actor entities:
|
||||
title: 'View unpublished Actor entities'
|
||||
|
||||
view all actor revisions:
|
||||
title: 'View all Actor revisions'
|
||||
|
||||
revert all actor revisions:
|
||||
title: 'Revert all Actor revisions'
|
||||
description: 'Role requires permission <em>view Actor revisions</em> and <em>edit rights</em> for actor entities in question or <em>administer actor entities</em>.'
|
||||
|
||||
delete all actor revisions:
|
||||
title: 'Delete all revisions'
|
||||
description: 'Role requires permission to <em>view Actor revisions</em> and <em>delete rights</em> for actor entities in question or <em>administer actor entities</em>.'
|
||||
add case entities:
|
||||
title: 'Create new Case entities'
|
||||
|
||||
administer case entities:
|
||||
title: 'Administer Case entities'
|
||||
description: 'Allow to access the administration form to configure Case entities.'
|
||||
restrict access: true
|
||||
|
||||
delete case entities:
|
||||
title: 'Delete Case entities'
|
||||
|
||||
edit case entities:
|
||||
title: 'Edit Case entities'
|
||||
|
||||
view published case entities:
|
||||
title: 'View published Case entities'
|
||||
|
||||
view unpublished case entities:
|
||||
title: 'View unpublished Case entities'
|
||||
|
||||
view all case revisions:
|
||||
title: 'View all Case revisions'
|
||||
|
||||
revert all case revisions:
|
||||
title: 'Revert all Case revisions'
|
||||
description: 'Role requires permission <em>view Case revisions</em> and <em>edit rights</em> for case entities in question or <em>administer case entities</em>.'
|
||||
|
||||
delete all case revisions:
|
||||
title: 'Delete all revisions'
|
||||
description: 'Role requires permission to <em>view Case revisions</em> and <em>delete rights</em> for case entities in question or <em>administer case entities</em>.'
|
||||
add activity entities:
|
||||
title: 'Create new Activity entities'
|
||||
|
||||
administer activity entities:
|
||||
title: 'Administer Activity entities'
|
||||
description: 'Allow to access the administration form to configure Activity entities.'
|
||||
restrict access: true
|
||||
|
||||
delete activity entities:
|
||||
title: 'Delete Activity entities'
|
||||
|
||||
edit activity entities:
|
||||
title: 'Edit Activity entities'
|
||||
|
||||
view published activity entities:
|
||||
title: 'View published Activity entities'
|
||||
|
||||
view unpublished activity entities:
|
||||
title: 'View unpublished Activity entities'
|
||||
|
||||
view all activity revisions:
|
||||
title: 'View all Activity revisions'
|
||||
|
||||
revert all activity revisions:
|
||||
title: 'Revert all Activity revisions'
|
||||
description: 'Role requires permission <em>view Activity revisions</em> and <em>edit rights</em> for activity entities in question or <em>administer activity entities</em>.'
|
||||
|
||||
delete all activity 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>.'
|
@ -0,0 +1,163 @@
|
||||
<?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\OCActivityInterface;
|
||||
|
||||
/**
|
||||
* Class OCActivityController.
|
||||
*
|
||||
* Returns responses for Activity routes.
|
||||
*/
|
||||
class OCActivityController extends ControllerBase implements ContainerInjectionInterface {
|
||||
|
||||
/**
|
||||
* Displays a Activity revision.
|
||||
*
|
||||
* @param int $oc_activity_revision
|
||||
* The Activity revision ID.
|
||||
*
|
||||
* @return array
|
||||
* An array suitable for drupal_render().
|
||||
*/
|
||||
public function revisionShow($oc_activity_revision) {
|
||||
$oc_activity = $this->entityManager()->getStorage('oc_activity')->loadRevision($oc_activity_revision);
|
||||
$view_builder = $this->entityManager()->getViewBuilder('oc_activity');
|
||||
|
||||
return $view_builder->view($oc_activity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Page title callback for a Activity revision.
|
||||
*
|
||||
* @param int $oc_activity_revision
|
||||
* The Activity revision ID.
|
||||
*
|
||||
* @return string
|
||||
* The page title.
|
||||
*/
|
||||
public function revisionPageTitle($oc_activity_revision) {
|
||||
$oc_activity = $this->entityManager()->getStorage('oc_activity')->loadRevision($oc_activity_revision);
|
||||
return $this->t('Revision of %title from %date', ['%title' => $oc_activity->label(), '%date' => format_date($oc_activity->getRevisionCreationTime())]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an overview table of older revisions of a Activity .
|
||||
*
|
||||
* @param \Drupal\opencase_entities\Entity\OCActivityInterface $oc_activity
|
||||
* A Activity object.
|
||||
*
|
||||
* @return array
|
||||
* An array as expected by drupal_render().
|
||||
*/
|
||||
public function revisionOverview(OCActivityInterface $oc_activity) {
|
||||
$account = $this->currentUser();
|
||||
$langcode = $oc_activity->language()->getId();
|
||||
$langname = $oc_activity->language()->getName();
|
||||
$languages = $oc_activity->getTranslationLanguages();
|
||||
$has_translations = (count($languages) > 1);
|
||||
$oc_activity_storage = $this->entityManager()->getStorage('oc_activity');
|
||||
|
||||
$build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => $oc_activity->label()]) : $this->t('Revisions for %title', ['%title' => $oc_activity->label()]);
|
||||
$header = [$this->t('Revision'), $this->t('Operations')];
|
||||
|
||||
$revert_permission = (($account->hasPermission("revert all activity revisions") || $account->hasPermission('administer activity entities')));
|
||||
$delete_permission = (($account->hasPermission("delete all activity revisions") || $account->hasPermission('administer activity entities')));
|
||||
|
||||
$rows = [];
|
||||
|
||||
$vids = $oc_activity_storage->revisionIds($oc_activity);
|
||||
|
||||
$latest_revision = TRUE;
|
||||
|
||||
foreach (array_reverse($vids) as $vid) {
|
||||
/** @var \Drupal\opencase_entities\OCActivityInterface $revision */
|
||||
$revision = $oc_activity_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 = \Drupal::service('date.formatter')->format($revision->getRevisionCreationTime(), 'short');
|
||||
if ($vid != $oc_activity->getRevisionId()) {
|
||||
$link = $this->l($date, new Url('entity.oc_activity.revision', ['oc_activity' => $oc_activity->id(), 'oc_activity_revision' => $vid]));
|
||||
}
|
||||
else {
|
||||
$link = $oc_activity->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' => \Drupal::service('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_activity.translation_revert', ['oc_activity' => $oc_activity->id(), 'oc_activity_revision' => $vid, 'langcode' => $langcode]) :
|
||||
Url::fromRoute('entity.oc_activity.revision_revert', ['oc_activity' => $oc_activity->id(), 'oc_activity_revision' => $vid]),
|
||||
];
|
||||
}
|
||||
|
||||
if ($delete_permission) {
|
||||
$links['delete'] = [
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => Url::fromRoute('entity.oc_activity.revision_delete', ['oc_activity' => $oc_activity->id(), 'oc_activity_revision' => $vid]),
|
||||
];
|
||||
}
|
||||
|
||||
$row[] = [
|
||||
'data' => [
|
||||
'#type' => 'operations',
|
||||
'#links' => $links,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
$build['oc_activity_revisions_table'] = [
|
||||
'#theme' => 'table',
|
||||
'#rows' => $rows,
|
||||
'#header' => $header,
|
||||
];
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
}
|
163
modules/opencase_entities/src/Controller/OCActorController.php
Normal file
163
modules/opencase_entities/src/Controller/OCActorController.php
Normal file
@ -0,0 +1,163 @@
|
||||
<?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\OCActorInterface;
|
||||
|
||||
/**
|
||||
* Class OCActorController.
|
||||
*
|
||||
* Returns responses for Actor routes.
|
||||
*/
|
||||
class OCActorController extends ControllerBase implements ContainerInjectionInterface {
|
||||
|
||||
/**
|
||||
* Displays a Actor revision.
|
||||
*
|
||||
* @param int $oc_actor_revision
|
||||
* The Actor revision ID.
|
||||
*
|
||||
* @return array
|
||||
* An array suitable for drupal_render().
|
||||
*/
|
||||
public function revisionShow($oc_actor_revision) {
|
||||
$oc_actor = $this->entityManager()->getStorage('oc_actor')->loadRevision($oc_actor_revision);
|
||||
$view_builder = $this->entityManager()->getViewBuilder('oc_actor');
|
||||
|
||||
return $view_builder->view($oc_actor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Page title callback for a Actor revision.
|
||||
*
|
||||
* @param int $oc_actor_revision
|
||||
* The Actor revision ID.
|
||||
*
|
||||
* @return string
|
||||
* The page title.
|
||||
*/
|
||||
public function revisionPageTitle($oc_actor_revision) {
|
||||
$oc_actor = $this->entityManager()->getStorage('oc_actor')->loadRevision($oc_actor_revision);
|
||||
return $this->t('Revision of %title from %date', ['%title' => $oc_actor->label(), '%date' => format_date($oc_actor->getRevisionCreationTime())]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an overview table of older revisions of a Actor .
|
||||
*
|
||||
* @param \Drupal\opencase_entities\Entity\OCActorInterface $oc_actor
|
||||
* A Actor object.
|
||||
*
|
||||
* @return array
|
||||
* An array as expected by drupal_render().
|
||||
*/
|
||||
public function revisionOverview(OCActorInterface $oc_actor) {
|
||||
$account = $this->currentUser();
|
||||
$langcode = $oc_actor->language()->getId();
|
||||
$langname = $oc_actor->language()->getName();
|
||||
$languages = $oc_actor->getTranslationLanguages();
|
||||
$has_translations = (count($languages) > 1);
|
||||
$oc_actor_storage = $this->entityManager()->getStorage('oc_actor');
|
||||
|
||||
$build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => $oc_actor->label()]) : $this->t('Revisions for %title', ['%title' => $oc_actor->label()]);
|
||||
$header = [$this->t('Revision'), $this->t('Operations')];
|
||||
|
||||
$revert_permission = (($account->hasPermission("revert all actor revisions") || $account->hasPermission('administer actor entities')));
|
||||
$delete_permission = (($account->hasPermission("delete all actor revisions") || $account->hasPermission('administer actor entities')));
|
||||
|
||||
$rows = [];
|
||||
|
||||
$vids = $oc_actor_storage->revisionIds($oc_actor);
|
||||
|
||||
$latest_revision = TRUE;
|
||||
|
||||
foreach (array_reverse($vids) as $vid) {
|
||||
/** @var \Drupal\opencase_entities\OCActorInterface $revision */
|
||||
$revision = $oc_actor_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 = \Drupal::service('date.formatter')->format($revision->getRevisionCreationTime(), 'short');
|
||||
if ($vid != $oc_actor->getRevisionId()) {
|
||||
$link = $this->l($date, new Url('entity.oc_actor.revision', ['oc_actor' => $oc_actor->id(), 'oc_actor_revision' => $vid]));
|
||||
}
|
||||
else {
|
||||
$link = $oc_actor->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' => \Drupal::service('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_actor.translation_revert', ['oc_actor' => $oc_actor->id(), 'oc_actor_revision' => $vid, 'langcode' => $langcode]) :
|
||||
Url::fromRoute('entity.oc_actor.revision_revert', ['oc_actor' => $oc_actor->id(), 'oc_actor_revision' => $vid]),
|
||||
];
|
||||
}
|
||||
|
||||
if ($delete_permission) {
|
||||
$links['delete'] = [
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => Url::fromRoute('entity.oc_actor.revision_delete', ['oc_actor' => $oc_actor->id(), 'oc_actor_revision' => $vid]),
|
||||
];
|
||||
}
|
||||
|
||||
$row[] = [
|
||||
'data' => [
|
||||
'#type' => 'operations',
|
||||
'#links' => $links,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
$build['oc_actor_revisions_table'] = [
|
||||
'#theme' => 'table',
|
||||
'#rows' => $rows,
|
||||
'#header' => $header,
|
||||
];
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
}
|
163
modules/opencase_entities/src/Controller/OCCaseController.php
Normal file
163
modules/opencase_entities/src/Controller/OCCaseController.php
Normal file
@ -0,0 +1,163 @@
|
||||
<?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\OCCaseInterface;
|
||||
|
||||
/**
|
||||
* Class OCCaseController.
|
||||
*
|
||||
* Returns responses for Case routes.
|
||||
*/
|
||||
class OCCaseController extends ControllerBase implements ContainerInjectionInterface {
|
||||
|
||||
/**
|
||||
* Displays a Case revision.
|
||||
*
|
||||
* @param int $oc_case_revision
|
||||
* The Case revision ID.
|
||||
*
|
||||
* @return array
|
||||
* An array suitable for drupal_render().
|
||||
*/
|
||||
public function revisionShow($oc_case_revision) {
|
||||
$oc_case = $this->entityManager()->getStorage('oc_case')->loadRevision($oc_case_revision);
|
||||
$view_builder = $this->entityManager()->getViewBuilder('oc_case');
|
||||
|
||||
return $view_builder->view($oc_case);
|
||||
}
|
||||
|
||||
/**
|
||||
* Page title callback for a Case revision.
|
||||
*
|
||||
* @param int $oc_case_revision
|
||||
* The Case revision ID.
|
||||
*
|
||||
* @return string
|
||||
* The page title.
|
||||
*/
|
||||
public function revisionPageTitle($oc_case_revision) {
|
||||
$oc_case = $this->entityManager()->getStorage('oc_case')->loadRevision($oc_case_revision);
|
||||
return $this->t('Revision of %title from %date', ['%title' => $oc_case->label(), '%date' => format_date($oc_case->getRevisionCreationTime())]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an overview table of older revisions of a Case .
|
||||
*
|
||||
* @param \Drupal\opencase_entities\Entity\OCCaseInterface $oc_case
|
||||
* A Case object.
|
||||
*
|
||||
* @return array
|
||||
* An array as expected by drupal_render().
|
||||
*/
|
||||
public function revisionOverview(OCCaseInterface $oc_case) {
|
||||
$account = $this->currentUser();
|
||||
$langcode = $oc_case->language()->getId();
|
||||
$langname = $oc_case->language()->getName();
|
||||
$languages = $oc_case->getTranslationLanguages();
|
||||
$has_translations = (count($languages) > 1);
|
||||
$oc_case_storage = $this->entityManager()->getStorage('oc_case');
|
||||
|
||||
$build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => $oc_case->label()]) : $this->t('Revisions for %title', ['%title' => $oc_case->label()]);
|
||||
$header = [$this->t('Revision'), $this->t('Operations')];
|
||||
|
||||
$revert_permission = (($account->hasPermission("revert all case revisions") || $account->hasPermission('administer case entities')));
|
||||
$delete_permission = (($account->hasPermission("delete all case revisions") || $account->hasPermission('administer case entities')));
|
||||
|
||||
$rows = [];
|
||||
|
||||
$vids = $oc_case_storage->revisionIds($oc_case);
|
||||
|
||||
$latest_revision = TRUE;
|
||||
|
||||
foreach (array_reverse($vids) as $vid) {
|
||||
/** @var \Drupal\opencase_entities\OCCaseInterface $revision */
|
||||
$revision = $oc_case_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 = \Drupal::service('date.formatter')->format($revision->getRevisionCreationTime(), 'short');
|
||||
if ($vid != $oc_case->getRevisionId()) {
|
||||
$link = $this->l($date, new Url('entity.oc_case.revision', ['oc_case' => $oc_case->id(), 'oc_case_revision' => $vid]));
|
||||
}
|
||||
else {
|
||||
$link = $oc_case->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' => \Drupal::service('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_case.translation_revert', ['oc_case' => $oc_case->id(), 'oc_case_revision' => $vid, 'langcode' => $langcode]) :
|
||||
Url::fromRoute('entity.oc_case.revision_revert', ['oc_case' => $oc_case->id(), 'oc_case_revision' => $vid]),
|
||||
];
|
||||
}
|
||||
|
||||
if ($delete_permission) {
|
||||
$links['delete'] = [
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => Url::fromRoute('entity.oc_case.revision_delete', ['oc_case' => $oc_case->id(), 'oc_case_revision' => $vid]),
|
||||
];
|
||||
}
|
||||
|
||||
$row[] = [
|
||||
'data' => [
|
||||
'#type' => 'operations',
|
||||
'#links' => $links,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
$build['oc_case_revisions_table'] = [
|
||||
'#theme' => 'table',
|
||||
'#rows' => $rows,
|
||||
'#header' => $header,
|
||||
];
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
}
|
281
modules/opencase_entities/src/Entity/OCActivity.php
Normal file
281
modules/opencase_entities/src/Entity/OCActivity.php
Normal file
@ -0,0 +1,281 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Entity\RevisionableContentEntityBase;
|
||||
use Drupal\Core\Entity\RevisionableInterface;
|
||||
use Drupal\Core\Entity\EntityChangedTrait;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Defines the Activity entity.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "oc_activity",
|
||||
* label = @Translation("Activity"),
|
||||
* bundle_label = @Translation("Activity type"),
|
||||
* handlers = {
|
||||
* "storage" = "Drupal\opencase_entities\OCActivityStorage",
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\opencase_entities\OCActivityListBuilder",
|
||||
* "views_data" = "Drupal\opencase_entities\Entity\OCActivityViewsData",
|
||||
* "translation" = "Drupal\opencase_entities\OCActivityTranslationHandler",
|
||||
*
|
||||
* "form" = {
|
||||
* "default" = "Drupal\opencase_entities\Form\OCActivityForm",
|
||||
* "add" = "Drupal\opencase_entities\Form\OCActivityForm",
|
||||
* "edit" = "Drupal\opencase_entities\Form\OCActivityForm",
|
||||
* "delete" = "Drupal\opencase_entities\Form\OCActivityDeleteForm",
|
||||
* },
|
||||
* "access" = "Drupal\opencase_entities\OCActivityAccessControlHandler",
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\opencase_entities\OCActivityHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* base_table = "oc_activity",
|
||||
* data_table = "oc_activity_field_data",
|
||||
* revision_table = "oc_activity_revision",
|
||||
* revision_data_table = "oc_activity_field_revision",
|
||||
* translatable = TRUE,
|
||||
* admin_permission = "administer activity entities",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "revision" = "vid",
|
||||
* "bundle" = "type",
|
||||
* "label" = "name",
|
||||
* "uuid" = "uuid",
|
||||
* "uid" = "user_id",
|
||||
* "langcode" = "langcode",
|
||||
* "status" = "status",
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/admin/opencase/oc_activity/{oc_activity}",
|
||||
* "add-page" = "/admin/opencase/oc_activity/add",
|
||||
* "add-form" = "/admin/opencase/oc_activity/add/{oc_activity_type}",
|
||||
* "edit-form" = "/admin/opencase/oc_activity/{oc_activity}/edit",
|
||||
* "delete-form" = "/admin/opencase/oc_activity/{oc_activity}/delete",
|
||||
* "version-history" = "/admin/opencase/oc_activity/{oc_activity}/revisions",
|
||||
* "revision" = "/admin/opencase/oc_activity/{oc_activity}/revisions/{oc_activity_revision}/view",
|
||||
* "revision_revert" = "/admin/opencase/oc_activity/{oc_activity}/revisions/{oc_activity_revision}/revert",
|
||||
* "revision_delete" = "/admin/opencase/oc_activity/{oc_activity}/revisions/{oc_activity_revision}/delete",
|
||||
* "translation_revert" = "/admin/opencase/oc_activity/{oc_activity}/revisions/{oc_activity_revision}/revert/{langcode}",
|
||||
* "collection" = "/admin/opencase/oc_activity",
|
||||
* },
|
||||
* bundle_entity_type = "oc_activity_type",
|
||||
* field_ui_base_route = "entity.oc_activity_type.edit_form"
|
||||
* )
|
||||
*/
|
||||
class OCActivity extends RevisionableContentEntityBase implements OCActivityInterface {
|
||||
|
||||
use EntityChangedTrait;
|
||||
|
||||
/**
|
||||
* {@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_activity 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 function isPublished() {
|
||||
return (bool) $this->getEntityKey('status');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPublished($published) {
|
||||
$this->set('status', $published ? TRUE : FALSE);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Authored by'))
|
||||
->setDescription(t('The user ID of author of the Activity 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 Activity 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'] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Publishing status'))
|
||||
->setDescription(t('A boolean indicating whether the Activity is published.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setDefaultValue(TRUE)
|
||||
->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;
|
||||
}
|
||||
|
||||
}
|
116
modules/opencase_entities/src/Entity/OCActivityInterface.php
Normal file
116
modules/opencase_entities/src/Entity/OCActivityInterface.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\RevisionLogInterface;
|
||||
use Drupal\Core\Entity\EntityChangedInterface;
|
||||
use Drupal\user\EntityOwnerInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining Activity entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
interface OCActivityInterface extends ContentEntityInterface, RevisionLogInterface, EntityChangedInterface, EntityOwnerInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
|
||||
/**
|
||||
* Gets the Activity name.
|
||||
*
|
||||
* @return string
|
||||
* Name of the Activity.
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Sets the Activity name.
|
||||
*
|
||||
* @param string $name
|
||||
* The Activity name.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCActivityInterface
|
||||
* The called Activity entity.
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* Gets the Activity creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* Creation timestamp of the Activity.
|
||||
*/
|
||||
public function getCreatedTime();
|
||||
|
||||
/**
|
||||
* Sets the Activity creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The Activity creation timestamp.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCActivityInterface
|
||||
* The called Activity entity.
|
||||
*/
|
||||
public function setCreatedTime($timestamp);
|
||||
|
||||
/**
|
||||
* Returns the Activity published status indicator.
|
||||
*
|
||||
* Unpublished Activity are only visible to restricted users.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the Activity is published.
|
||||
*/
|
||||
public function isPublished();
|
||||
|
||||
/**
|
||||
* Sets the published status of a Activity.
|
||||
*
|
||||
* @param bool $published
|
||||
* TRUE to set this Activity to published, FALSE to set it to unpublished.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCActivityInterface
|
||||
* The called Activity entity.
|
||||
*/
|
||||
public function setPublished($published);
|
||||
|
||||
/**
|
||||
* Gets the Activity revision creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* The UNIX timestamp of when this revision was created.
|
||||
*/
|
||||
public function getRevisionCreationTime();
|
||||
|
||||
/**
|
||||
* Sets the Activity revision creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The UNIX timestamp of when this revision was created.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCActivityInterface
|
||||
* The called Activity entity.
|
||||
*/
|
||||
public function setRevisionCreationTime($timestamp);
|
||||
|
||||
/**
|
||||
* Gets the Activity revision author.
|
||||
*
|
||||
* @return \Drupal\user\UserInterface
|
||||
* The user entity for the revision author.
|
||||
*/
|
||||
public function getRevisionUser();
|
||||
|
||||
/**
|
||||
* Sets the Activity revision author.
|
||||
*
|
||||
* @param int $uid
|
||||
* The user ID of the revision author.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCActivityInterface
|
||||
* The called Activity entity.
|
||||
*/
|
||||
public function setRevisionUserId($uid);
|
||||
|
||||
}
|
58
modules/opencase_entities/src/Entity/OCActivityType.php
Normal file
58
modules/opencase_entities/src/Entity/OCActivityType.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
||||
|
||||
/**
|
||||
* Defines the Activity type entity.
|
||||
*
|
||||
* @ConfigEntityType(
|
||||
* id = "oc_activity_type",
|
||||
* label = @Translation("Activity type"),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\opencase_entities\OCActivityTypeListBuilder",
|
||||
* "form" = {
|
||||
* "add" = "Drupal\opencase_entities\Form\OCActivityTypeForm",
|
||||
* "edit" = "Drupal\opencase_entities\Form\OCActivityTypeForm",
|
||||
* "delete" = "Drupal\opencase_entities\Form\OCActivityTypeDeleteForm"
|
||||
* },
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\opencase_entities\OCActivityTypeHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* config_prefix = "oc_activity_type",
|
||||
* admin_permission = "administer site configuration",
|
||||
* bundle_of = "oc_activity",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label",
|
||||
* "uuid" = "uuid"
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/admin/opencase/oc_activity_type/{oc_activity_type}",
|
||||
* "add-form" = "/admin/opencase/oc_activity_type/add",
|
||||
* "edit-form" = "/admin/opencase/oc_activity_type/{oc_activity_type}/edit",
|
||||
* "delete-form" = "/admin/opencase/oc_activity_type/{oc_activity_type}/delete",
|
||||
* "collection" = "/admin/opencase/oc_activity_type"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class OCActivityType extends ConfigEntityBundleBase implements OCActivityTypeInterface {
|
||||
|
||||
/**
|
||||
* The Activity type ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* The Activity 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 Activity type entities.
|
||||
*/
|
||||
interface OCActivityTypeInterface extends ConfigEntityInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
}
|
24
modules/opencase_entities/src/Entity/OCActivityViewsData.php
Normal file
24
modules/opencase_entities/src/Entity/OCActivityViewsData.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\views\EntityViewsData;
|
||||
|
||||
/**
|
||||
* Provides Views data for Activity entities.
|
||||
*/
|
||||
class OCActivityViewsData extends EntityViewsData {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getViewsData() {
|
||||
$data = parent::getViewsData();
|
||||
|
||||
// Additional information for Views integration, such as table joins, can be
|
||||
// put here.
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
281
modules/opencase_entities/src/Entity/OCActor.php
Normal file
281
modules/opencase_entities/src/Entity/OCActor.php
Normal file
@ -0,0 +1,281 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Entity\RevisionableContentEntityBase;
|
||||
use Drupal\Core\Entity\RevisionableInterface;
|
||||
use Drupal\Core\Entity\EntityChangedTrait;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Defines the Actor entity.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "oc_actor",
|
||||
* label = @Translation("Actor"),
|
||||
* bundle_label = @Translation("Actor type"),
|
||||
* handlers = {
|
||||
* "storage" = "Drupal\opencase_entities\OCActorStorage",
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\opencase_entities\OCActorListBuilder",
|
||||
* "views_data" = "Drupal\opencase_entities\Entity\OCActorViewsData",
|
||||
* "translation" = "Drupal\opencase_entities\OCActorTranslationHandler",
|
||||
*
|
||||
* "form" = {
|
||||
* "default" = "Drupal\opencase_entities\Form\OCActorForm",
|
||||
* "add" = "Drupal\opencase_entities\Form\OCActorForm",
|
||||
* "edit" = "Drupal\opencase_entities\Form\OCActorForm",
|
||||
* "delete" = "Drupal\opencase_entities\Form\OCActorDeleteForm",
|
||||
* },
|
||||
* "access" = "Drupal\opencase_entities\OCActorAccessControlHandler",
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\opencase_entities\OCActorHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* base_table = "oc_actor",
|
||||
* data_table = "oc_actor_field_data",
|
||||
* revision_table = "oc_actor_revision",
|
||||
* revision_data_table = "oc_actor_field_revision",
|
||||
* translatable = TRUE,
|
||||
* admin_permission = "administer actor entities",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "revision" = "vid",
|
||||
* "bundle" = "type",
|
||||
* "label" = "name",
|
||||
* "uuid" = "uuid",
|
||||
* "uid" = "user_id",
|
||||
* "langcode" = "langcode",
|
||||
* "status" = "status",
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/admin/opencase/oc_actor/{oc_actor}",
|
||||
* "add-page" = "/admin/opencase/oc_actor/add",
|
||||
* "add-form" = "/admin/opencase/oc_actor/add/{oc_actor_type}",
|
||||
* "edit-form" = "/admin/opencase/oc_actor/{oc_actor}/edit",
|
||||
* "delete-form" = "/admin/opencase/oc_actor/{oc_actor}/delete",
|
||||
* "version-history" = "/admin/opencase/oc_actor/{oc_actor}/revisions",
|
||||
* "revision" = "/admin/opencase/oc_actor/{oc_actor}/revisions/{oc_actor_revision}/view",
|
||||
* "revision_revert" = "/admin/opencase/oc_actor/{oc_actor}/revisions/{oc_actor_revision}/revert",
|
||||
* "revision_delete" = "/admin/opencase/oc_actor/{oc_actor}/revisions/{oc_actor_revision}/delete",
|
||||
* "translation_revert" = "/admin/opencase/oc_actor/{oc_actor}/revisions/{oc_actor_revision}/revert/{langcode}",
|
||||
* "collection" = "/admin/opencase/oc_actor",
|
||||
* },
|
||||
* bundle_entity_type = "oc_actor_type",
|
||||
* field_ui_base_route = "entity.oc_actor_type.edit_form"
|
||||
* )
|
||||
*/
|
||||
class OCActor extends RevisionableContentEntityBase implements OCActorInterface {
|
||||
|
||||
use EntityChangedTrait;
|
||||
|
||||
/**
|
||||
* {@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_actor 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 function isPublished() {
|
||||
return (bool) $this->getEntityKey('status');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPublished($published) {
|
||||
$this->set('status', $published ? TRUE : FALSE);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Authored by'))
|
||||
->setDescription(t('The user ID of author of the Actor 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 Actor 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'] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Publishing status'))
|
||||
->setDescription(t('A boolean indicating whether the Actor is published.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setDefaultValue(TRUE)
|
||||
->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;
|
||||
}
|
||||
|
||||
}
|
116
modules/opencase_entities/src/Entity/OCActorInterface.php
Normal file
116
modules/opencase_entities/src/Entity/OCActorInterface.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\RevisionLogInterface;
|
||||
use Drupal\Core\Entity\EntityChangedInterface;
|
||||
use Drupal\user\EntityOwnerInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining Actor entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
interface OCActorInterface extends ContentEntityInterface, RevisionLogInterface, EntityChangedInterface, EntityOwnerInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
|
||||
/**
|
||||
* Gets the Actor name.
|
||||
*
|
||||
* @return string
|
||||
* Name of the Actor.
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Sets the Actor name.
|
||||
*
|
||||
* @param string $name
|
||||
* The Actor name.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCActorInterface
|
||||
* The called Actor entity.
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* Gets the Actor creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* Creation timestamp of the Actor.
|
||||
*/
|
||||
public function getCreatedTime();
|
||||
|
||||
/**
|
||||
* Sets the Actor creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The Actor creation timestamp.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCActorInterface
|
||||
* The called Actor entity.
|
||||
*/
|
||||
public function setCreatedTime($timestamp);
|
||||
|
||||
/**
|
||||
* Returns the Actor published status indicator.
|
||||
*
|
||||
* Unpublished Actor are only visible to restricted users.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the Actor is published.
|
||||
*/
|
||||
public function isPublished();
|
||||
|
||||
/**
|
||||
* Sets the published status of a Actor.
|
||||
*
|
||||
* @param bool $published
|
||||
* TRUE to set this Actor to published, FALSE to set it to unpublished.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCActorInterface
|
||||
* The called Actor entity.
|
||||
*/
|
||||
public function setPublished($published);
|
||||
|
||||
/**
|
||||
* Gets the Actor revision creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* The UNIX timestamp of when this revision was created.
|
||||
*/
|
||||
public function getRevisionCreationTime();
|
||||
|
||||
/**
|
||||
* Sets the Actor revision creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The UNIX timestamp of when this revision was created.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCActorInterface
|
||||
* The called Actor entity.
|
||||
*/
|
||||
public function setRevisionCreationTime($timestamp);
|
||||
|
||||
/**
|
||||
* Gets the Actor revision author.
|
||||
*
|
||||
* @return \Drupal\user\UserInterface
|
||||
* The user entity for the revision author.
|
||||
*/
|
||||
public function getRevisionUser();
|
||||
|
||||
/**
|
||||
* Sets the Actor revision author.
|
||||
*
|
||||
* @param int $uid
|
||||
* The user ID of the revision author.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCActorInterface
|
||||
* The called Actor entity.
|
||||
*/
|
||||
public function setRevisionUserId($uid);
|
||||
|
||||
}
|
58
modules/opencase_entities/src/Entity/OCActorType.php
Normal file
58
modules/opencase_entities/src/Entity/OCActorType.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
||||
|
||||
/**
|
||||
* Defines the Actor type entity.
|
||||
*
|
||||
* @ConfigEntityType(
|
||||
* id = "oc_actor_type",
|
||||
* label = @Translation("Actor type"),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\opencase_entities\OCActorTypeListBuilder",
|
||||
* "form" = {
|
||||
* "add" = "Drupal\opencase_entities\Form\OCActorTypeForm",
|
||||
* "edit" = "Drupal\opencase_entities\Form\OCActorTypeForm",
|
||||
* "delete" = "Drupal\opencase_entities\Form\OCActorTypeDeleteForm"
|
||||
* },
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\opencase_entities\OCActorTypeHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* config_prefix = "oc_actor_type",
|
||||
* admin_permission = "administer site configuration",
|
||||
* bundle_of = "oc_actor",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label",
|
||||
* "uuid" = "uuid"
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/admin/opencase/oc_actor_type/{oc_actor_type}",
|
||||
* "add-form" = "/admin/opencase/oc_actor_type/add",
|
||||
* "edit-form" = "/admin/opencase/oc_actor_type/{oc_actor_type}/edit",
|
||||
* "delete-form" = "/admin/opencase/oc_actor_type/{oc_actor_type}/delete",
|
||||
* "collection" = "/admin/opencase/oc_actor_type"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class OCActorType extends ConfigEntityBundleBase implements OCActorTypeInterface {
|
||||
|
||||
/**
|
||||
* The Actor type ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* The Actor 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 Actor type entities.
|
||||
*/
|
||||
interface OCActorTypeInterface extends ConfigEntityInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
}
|
24
modules/opencase_entities/src/Entity/OCActorViewsData.php
Normal file
24
modules/opencase_entities/src/Entity/OCActorViewsData.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\views\EntityViewsData;
|
||||
|
||||
/**
|
||||
* Provides Views data for Actor entities.
|
||||
*/
|
||||
class OCActorViewsData extends EntityViewsData {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getViewsData() {
|
||||
$data = parent::getViewsData();
|
||||
|
||||
// Additional information for Views integration, such as table joins, can be
|
||||
// put here.
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
281
modules/opencase_entities/src/Entity/OCCase.php
Normal file
281
modules/opencase_entities/src/Entity/OCCase.php
Normal file
@ -0,0 +1,281 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Entity\RevisionableContentEntityBase;
|
||||
use Drupal\Core\Entity\RevisionableInterface;
|
||||
use Drupal\Core\Entity\EntityChangedTrait;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Defines the Case entity.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "oc_case",
|
||||
* label = @Translation("Case"),
|
||||
* bundle_label = @Translation("Case type"),
|
||||
* handlers = {
|
||||
* "storage" = "Drupal\opencase_entities\OCCaseStorage",
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\opencase_entities\OCCaseListBuilder",
|
||||
* "views_data" = "Drupal\opencase_entities\Entity\OCCaseViewsData",
|
||||
* "translation" = "Drupal\opencase_entities\OCCaseTranslationHandler",
|
||||
*
|
||||
* "form" = {
|
||||
* "default" = "Drupal\opencase_entities\Form\OCCaseForm",
|
||||
* "add" = "Drupal\opencase_entities\Form\OCCaseForm",
|
||||
* "edit" = "Drupal\opencase_entities\Form\OCCaseForm",
|
||||
* "delete" = "Drupal\opencase_entities\Form\OCCaseDeleteForm",
|
||||
* },
|
||||
* "access" = "Drupal\opencase_entities\OCCaseAccessControlHandler",
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\opencase_entities\OCCaseHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* base_table = "oc_case",
|
||||
* data_table = "oc_case_field_data",
|
||||
* revision_table = "oc_case_revision",
|
||||
* revision_data_table = "oc_case_field_revision",
|
||||
* translatable = TRUE,
|
||||
* admin_permission = "administer case entities",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "revision" = "vid",
|
||||
* "bundle" = "type",
|
||||
* "label" = "name",
|
||||
* "uuid" = "uuid",
|
||||
* "uid" = "user_id",
|
||||
* "langcode" = "langcode",
|
||||
* "status" = "status",
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/admin/opencase/oc_case/{oc_case}",
|
||||
* "add-page" = "/admin/opencase/oc_case/add",
|
||||
* "add-form" = "/admin/opencase/oc_case/add/{oc_case_type}",
|
||||
* "edit-form" = "/admin/opencase/oc_case/{oc_case}/edit",
|
||||
* "delete-form" = "/admin/opencase/oc_case/{oc_case}/delete",
|
||||
* "version-history" = "/admin/opencase/oc_case/{oc_case}/revisions",
|
||||
* "revision" = "/admin/opencase/oc_case/{oc_case}/revisions/{oc_case_revision}/view",
|
||||
* "revision_revert" = "/admin/opencase/oc_case/{oc_case}/revisions/{oc_case_revision}/revert",
|
||||
* "revision_delete" = "/admin/opencase/oc_case/{oc_case}/revisions/{oc_case_revision}/delete",
|
||||
* "translation_revert" = "/admin/opencase/oc_case/{oc_case}/revisions/{oc_case_revision}/revert/{langcode}",
|
||||
* "collection" = "/admin/opencase/oc_case",
|
||||
* },
|
||||
* bundle_entity_type = "oc_case_type",
|
||||
* field_ui_base_route = "entity.oc_case_type.edit_form"
|
||||
* )
|
||||
*/
|
||||
class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
|
||||
|
||||
use EntityChangedTrait;
|
||||
|
||||
/**
|
||||
* {@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_case 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 function isPublished() {
|
||||
return (bool) $this->getEntityKey('status');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPublished($published) {
|
||||
$this->set('status', $published ? TRUE : FALSE);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Authored by'))
|
||||
->setDescription(t('The user ID of author of the Case 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 Case 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'] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Publishing status'))
|
||||
->setDescription(t('A boolean indicating whether the Case is published.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setDefaultValue(TRUE)
|
||||
->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;
|
||||
}
|
||||
|
||||
}
|
116
modules/opencase_entities/src/Entity/OCCaseInterface.php
Normal file
116
modules/opencase_entities/src/Entity/OCCaseInterface.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\RevisionLogInterface;
|
||||
use Drupal\Core\Entity\EntityChangedInterface;
|
||||
use Drupal\user\EntityOwnerInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining Case entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
interface OCCaseInterface extends ContentEntityInterface, RevisionLogInterface, EntityChangedInterface, EntityOwnerInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
|
||||
/**
|
||||
* Gets the Case name.
|
||||
*
|
||||
* @return string
|
||||
* Name of the Case.
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Sets the Case name.
|
||||
*
|
||||
* @param string $name
|
||||
* The Case name.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCCaseInterface
|
||||
* The called Case entity.
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* Gets the Case creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* Creation timestamp of the Case.
|
||||
*/
|
||||
public function getCreatedTime();
|
||||
|
||||
/**
|
||||
* Sets the Case creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The Case creation timestamp.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCCaseInterface
|
||||
* The called Case entity.
|
||||
*/
|
||||
public function setCreatedTime($timestamp);
|
||||
|
||||
/**
|
||||
* Returns the Case published status indicator.
|
||||
*
|
||||
* Unpublished Case are only visible to restricted users.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the Case is published.
|
||||
*/
|
||||
public function isPublished();
|
||||
|
||||
/**
|
||||
* Sets the published status of a Case.
|
||||
*
|
||||
* @param bool $published
|
||||
* TRUE to set this Case to published, FALSE to set it to unpublished.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCCaseInterface
|
||||
* The called Case entity.
|
||||
*/
|
||||
public function setPublished($published);
|
||||
|
||||
/**
|
||||
* Gets the Case revision creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* The UNIX timestamp of when this revision was created.
|
||||
*/
|
||||
public function getRevisionCreationTime();
|
||||
|
||||
/**
|
||||
* Sets the Case revision creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The UNIX timestamp of when this revision was created.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCCaseInterface
|
||||
* The called Case entity.
|
||||
*/
|
||||
public function setRevisionCreationTime($timestamp);
|
||||
|
||||
/**
|
||||
* Gets the Case revision author.
|
||||
*
|
||||
* @return \Drupal\user\UserInterface
|
||||
* The user entity for the revision author.
|
||||
*/
|
||||
public function getRevisionUser();
|
||||
|
||||
/**
|
||||
* Sets the Case revision author.
|
||||
*
|
||||
* @param int $uid
|
||||
* The user ID of the revision author.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCCaseInterface
|
||||
* The called Case entity.
|
||||
*/
|
||||
public function setRevisionUserId($uid);
|
||||
|
||||
}
|
58
modules/opencase_entities/src/Entity/OCCaseType.php
Normal file
58
modules/opencase_entities/src/Entity/OCCaseType.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
||||
|
||||
/**
|
||||
* Defines the Case type entity.
|
||||
*
|
||||
* @ConfigEntityType(
|
||||
* id = "oc_case_type",
|
||||
* label = @Translation("Case type"),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\opencase_entities\OCCaseTypeListBuilder",
|
||||
* "form" = {
|
||||
* "add" = "Drupal\opencase_entities\Form\OCCaseTypeForm",
|
||||
* "edit" = "Drupal\opencase_entities\Form\OCCaseTypeForm",
|
||||
* "delete" = "Drupal\opencase_entities\Form\OCCaseTypeDeleteForm"
|
||||
* },
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\opencase_entities\OCCaseTypeHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* config_prefix = "oc_case_type",
|
||||
* admin_permission = "administer site configuration",
|
||||
* bundle_of = "oc_case",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label",
|
||||
* "uuid" = "uuid"
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/admin/opencase/oc_case_type/{oc_case_type}",
|
||||
* "add-form" = "/admin/opencase/oc_case_type/add",
|
||||
* "edit-form" = "/admin/opencase/oc_case_type/{oc_case_type}/edit",
|
||||
* "delete-form" = "/admin/opencase/oc_case_type/{oc_case_type}/delete",
|
||||
* "collection" = "/admin/opencase/oc_case_type"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class OCCaseType extends ConfigEntityBundleBase implements OCCaseTypeInterface {
|
||||
|
||||
/**
|
||||
* The Case type ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* The Case type label.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
}
|
13
modules/opencase_entities/src/Entity/OCCaseTypeInterface.php
Normal file
13
modules/opencase_entities/src/Entity/OCCaseTypeInterface.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining Case type entities.
|
||||
*/
|
||||
interface OCCaseTypeInterface extends ConfigEntityInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
}
|
24
modules/opencase_entities/src/Entity/OCCaseViewsData.php
Normal file
24
modules/opencase_entities/src/Entity/OCCaseViewsData.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Entity;
|
||||
|
||||
use Drupal\views\EntityViewsData;
|
||||
|
||||
/**
|
||||
* Provides Views data for Case entities.
|
||||
*/
|
||||
class OCCaseViewsData extends EntityViewsData {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getViewsData() {
|
||||
$data = parent::getViewsData();
|
||||
|
||||
// Additional information for Views integration, such as table joins, can be
|
||||
// put here.
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
15
modules/opencase_entities/src/Form/OCActivityDeleteForm.php
Normal file
15
modules/opencase_entities/src/Form/OCActivityDeleteForm.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityDeleteForm;
|
||||
|
||||
/**
|
||||
* Provides a form for deleting Activity entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActivityDeleteForm extends ContentEntityDeleteForm {
|
||||
|
||||
|
||||
}
|
71
modules/opencase_entities/src/Form/OCActivityForm.php
Normal file
71
modules/opencase_entities/src/Form/OCActivityForm.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Form controller for Activity edit forms.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActivityForm extends ContentEntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
/* @var $entity \Drupal\opencase_entities\Entity\OCActivity */
|
||||
$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,
|
||||
];
|
||||
}
|
||||
|
||||
$entity = $this->entity;
|
||||
|
||||
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(REQUEST_TIME);
|
||||
$entity->setRevisionUserId(\Drupal::currentUser()->id());
|
||||
}
|
||||
else {
|
||||
$entity->setNewRevision(FALSE);
|
||||
}
|
||||
|
||||
$status = parent::save($form, $form_state);
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
drupal_set_message($this->t('Created the %label Activity.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Activity.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirect('entity.oc_activity.canonical', ['oc_activity' => $entity->id()]);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
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 Activity revision.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActivityRevisionDeleteForm extends ConfirmFormBase {
|
||||
|
||||
|
||||
/**
|
||||
* The Activity revision.
|
||||
*
|
||||
* @var \Drupal\opencase_entities\Entity\OCActivityInterface
|
||||
*/
|
||||
protected $revision;
|
||||
|
||||
/**
|
||||
* The Activity storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $OCActivityStorage;
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
* @var \Drupal\Core\Database\Connection
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* Constructs a new OCActivityRevisionDeleteForm.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
|
||||
* The entity storage.
|
||||
* @param \Drupal\Core\Database\Connection $connection
|
||||
* The database connection.
|
||||
*/
|
||||
public function __construct(EntityStorageInterface $entity_storage, Connection $connection) {
|
||||
$this->OCActivityStorage = $entity_storage;
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
$entity_manager = $container->get('entity.manager');
|
||||
return new static(
|
||||
$entity_manager->getStorage('oc_activity'),
|
||||
$container->get('database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'oc_activity_revision_delete_confirm';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return 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_activity.version_history', ['oc_activity' => $this->revision->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return t('Delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $oc_activity_revision = NULL) {
|
||||
$this->revision = $this->OCActivityStorage->loadRevision($oc_activity_revision);
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->OCActivityStorage->deleteRevision($this->revision->getRevisionId());
|
||||
|
||||
$this->logger('content')->notice('Activity: deleted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
|
||||
drupal_set_message(t('Revision from %revision-date of Activity %title has been deleted.', ['%revision-date' => format_date($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()]));
|
||||
$form_state->setRedirect(
|
||||
'entity.oc_activity.canonical',
|
||||
['oc_activity' => $this->revision->id()]
|
||||
);
|
||||
if ($this->connection->query('SELECT COUNT(DISTINCT vid) FROM {oc_activity_field_revision} WHERE id = :id', [':id' => $this->revision->id()])->fetchField() > 1) {
|
||||
$form_state->setRedirect(
|
||||
'entity.oc_activity.version_history',
|
||||
['oc_activity' => $this->revision->id()]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Datetime\DateFormatterInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Form\ConfirmFormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\opencase_entities\Entity\OCActivityInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for reverting a Activity revision.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActivityRevisionRevertForm extends ConfirmFormBase {
|
||||
|
||||
|
||||
/**
|
||||
* The Activity revision.
|
||||
*
|
||||
* @var \Drupal\opencase_entities\Entity\OCActivityInterface
|
||||
*/
|
||||
protected $revision;
|
||||
|
||||
/**
|
||||
* The Activity storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $OCActivityStorage;
|
||||
|
||||
/**
|
||||
* The date formatter service.
|
||||
*
|
||||
* @var \Drupal\Core\Datetime\DateFormatterInterface
|
||||
*/
|
||||
protected $dateFormatter;
|
||||
|
||||
/**
|
||||
* Constructs a new OCActivityRevisionRevertForm.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
|
||||
* The Activity storage.
|
||||
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
|
||||
* The date formatter service.
|
||||
*/
|
||||
public function __construct(EntityStorageInterface $entity_storage, DateFormatterInterface $date_formatter) {
|
||||
$this->OCActivityStorage = $entity_storage;
|
||||
$this->dateFormatter = $date_formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager')->getStorage('oc_activity'),
|
||||
$container->get('date.formatter')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'oc_activity_revision_revert_confirm';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return 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_activity.version_history', ['oc_activity' => $this->revision->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return t('Revert');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $oc_activity_revision = NULL) {
|
||||
$this->revision = $this->OCActivityStorage->loadRevision($oc_activity_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 = t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]);
|
||||
$this->revision->save();
|
||||
|
||||
$this->logger('content')->notice('Activity: reverted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
|
||||
drupal_set_message(t('Activity %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_activity.version_history',
|
||||
['oc_activity' => $this->revision->id()]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a revision to be reverted.
|
||||
*
|
||||
* @param \Drupal\opencase_entities\Entity\OCActivityInterface $revision
|
||||
* The revision to be reverted.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCActivityInterface
|
||||
* The prepared revision ready to be stored.
|
||||
*/
|
||||
protected function prepareRevertedRevision(OCActivityInterface $revision, FormStateInterface $form_state) {
|
||||
$revision->setNewRevision();
|
||||
$revision->isDefaultRevision(TRUE);
|
||||
$revision->setRevisionCreationTime(REQUEST_TIME);
|
||||
|
||||
return $revision;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Datetime\DateFormatterInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\opencase_entities\Entity\OCActivityInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for reverting a Activity revision for a single translation.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActivityRevisionRevertTranslationForm extends OCActivityRevisionRevertForm {
|
||||
|
||||
|
||||
/**
|
||||
* The language to be reverted.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $langcode;
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* Constructs a new OCActivityRevisionRevertTranslationForm.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
|
||||
* The Activity storage.
|
||||
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
|
||||
* The date formatter service.
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
* The language manager.
|
||||
*/
|
||||
public function __construct(EntityStorageInterface $entity_storage, DateFormatterInterface $date_formatter, LanguageManagerInterface $language_manager) {
|
||||
parent::__construct($entity_storage, $date_formatter);
|
||||
$this->languageManager = $language_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager')->getStorage('oc_activity'),
|
||||
$container->get('date.formatter'),
|
||||
$container->get('language_manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'oc_activity_revision_revert_translation_confirm';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return 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_activity_revision = NULL, $langcode = NULL) {
|
||||
$this->langcode = $langcode;
|
||||
$form = parent::buildForm($form, $form_state, $oc_activity_revision);
|
||||
|
||||
$form['revert_untranslated_fields'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Revert content shared among translations'),
|
||||
'#default_value' => FALSE,
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function prepareRevertedRevision(OCActivityInterface $revision, FormStateInterface $form_state) {
|
||||
$revert_untranslated_fields = $form_state->getValue('revert_untranslated_fields');
|
||||
|
||||
/** @var \Drupal\opencase_entities\Entity\OCActivityInterface $default_revision */
|
||||
$latest_revision = $this->OCActivityStorage->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 OCActivitySettingsForm.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActivitySettingsForm extends FormBase {
|
||||
|
||||
/**
|
||||
* Returns a unique string identifying the form.
|
||||
*
|
||||
* @return string
|
||||
* The unique string identifying the form.
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'ocactivity_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 Activity 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['ocactivity_settings']['#markup'] = 'Settings form for Activity entities. Manage field settings here.';
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?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 Activity type entities.
|
||||
*/
|
||||
class OCActivityTypeDeleteForm 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_activity_type.collection');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return $this->t('Delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->entity->delete();
|
||||
|
||||
drupal_set_message(
|
||||
$this->t('content @type: deleted @label.',
|
||||
[
|
||||
'@type' => $this->entity->bundle(),
|
||||
'@label' => $this->entity->label(),
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||
}
|
||||
|
||||
}
|
65
modules/opencase_entities/src/Form/OCActivityTypeForm.php
Normal file
65
modules/opencase_entities/src/Form/OCActivityTypeForm.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class OCActivityTypeForm.
|
||||
*/
|
||||
class OCActivityTypeForm extends EntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$form = parent::form($form, $form_state);
|
||||
|
||||
$oc_activity_type = $this->entity;
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Label'),
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => $oc_activity_type->label(),
|
||||
'#description' => $this->t("Label for the Activity type."),
|
||||
'#required' => TRUE,
|
||||
];
|
||||
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#default_value' => $oc_activity_type->id(),
|
||||
'#machine_name' => [
|
||||
'exists' => '\Drupal\opencase_entities\Entity\OCActivityType::load',
|
||||
],
|
||||
'#disabled' => !$oc_activity_type->isNew(),
|
||||
];
|
||||
|
||||
/* You will need additional form elements for your custom properties. */
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$oc_activity_type = $this->entity;
|
||||
$status = $oc_activity_type->save();
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
drupal_set_message($this->t('Created the %label Activity type.', [
|
||||
'%label' => $oc_activity_type->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Activity type.', [
|
||||
'%label' => $oc_activity_type->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirectUrl($oc_activity_type->toUrl('collection'));
|
||||
}
|
||||
|
||||
}
|
15
modules/opencase_entities/src/Form/OCActorDeleteForm.php
Normal file
15
modules/opencase_entities/src/Form/OCActorDeleteForm.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityDeleteForm;
|
||||
|
||||
/**
|
||||
* Provides a form for deleting Actor entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActorDeleteForm extends ContentEntityDeleteForm {
|
||||
|
||||
|
||||
}
|
71
modules/opencase_entities/src/Form/OCActorForm.php
Normal file
71
modules/opencase_entities/src/Form/OCActorForm.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Form controller for Actor edit forms.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActorForm extends ContentEntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
/* @var $entity \Drupal\opencase_entities\Entity\OCActor */
|
||||
$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,
|
||||
];
|
||||
}
|
||||
|
||||
$entity = $this->entity;
|
||||
|
||||
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(REQUEST_TIME);
|
||||
$entity->setRevisionUserId(\Drupal::currentUser()->id());
|
||||
}
|
||||
else {
|
||||
$entity->setNewRevision(FALSE);
|
||||
}
|
||||
|
||||
$status = parent::save($form, $form_state);
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
drupal_set_message($this->t('Created the %label Actor.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Actor.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirect('entity.oc_actor.canonical', ['oc_actor' => $entity->id()]);
|
||||
}
|
||||
|
||||
}
|
123
modules/opencase_entities/src/Form/OCActorRevisionDeleteForm.php
Normal file
123
modules/opencase_entities/src/Form/OCActorRevisionDeleteForm.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
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 Actor revision.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActorRevisionDeleteForm extends ConfirmFormBase {
|
||||
|
||||
|
||||
/**
|
||||
* The Actor revision.
|
||||
*
|
||||
* @var \Drupal\opencase_entities\Entity\OCActorInterface
|
||||
*/
|
||||
protected $revision;
|
||||
|
||||
/**
|
||||
* The Actor storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $OCActorStorage;
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
* @var \Drupal\Core\Database\Connection
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* Constructs a new OCActorRevisionDeleteForm.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
|
||||
* The entity storage.
|
||||
* @param \Drupal\Core\Database\Connection $connection
|
||||
* The database connection.
|
||||
*/
|
||||
public function __construct(EntityStorageInterface $entity_storage, Connection $connection) {
|
||||
$this->OCActorStorage = $entity_storage;
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
$entity_manager = $container->get('entity.manager');
|
||||
return new static(
|
||||
$entity_manager->getStorage('oc_actor'),
|
||||
$container->get('database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'oc_actor_revision_delete_confirm';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return 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_actor.version_history', ['oc_actor' => $this->revision->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return t('Delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $oc_actor_revision = NULL) {
|
||||
$this->revision = $this->OCActorStorage->loadRevision($oc_actor_revision);
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->OCActorStorage->deleteRevision($this->revision->getRevisionId());
|
||||
|
||||
$this->logger('content')->notice('Actor: deleted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
|
||||
drupal_set_message(t('Revision from %revision-date of Actor %title has been deleted.', ['%revision-date' => format_date($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()]));
|
||||
$form_state->setRedirect(
|
||||
'entity.oc_actor.canonical',
|
||||
['oc_actor' => $this->revision->id()]
|
||||
);
|
||||
if ($this->connection->query('SELECT COUNT(DISTINCT vid) FROM {oc_actor_field_revision} WHERE id = :id', [':id' => $this->revision->id()])->fetchField() > 1) {
|
||||
$form_state->setRedirect(
|
||||
'entity.oc_actor.version_history',
|
||||
['oc_actor' => $this->revision->id()]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
149
modules/opencase_entities/src/Form/OCActorRevisionRevertForm.php
Normal file
149
modules/opencase_entities/src/Form/OCActorRevisionRevertForm.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Datetime\DateFormatterInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Form\ConfirmFormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\opencase_entities\Entity\OCActorInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for reverting a Actor revision.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActorRevisionRevertForm extends ConfirmFormBase {
|
||||
|
||||
|
||||
/**
|
||||
* The Actor revision.
|
||||
*
|
||||
* @var \Drupal\opencase_entities\Entity\OCActorInterface
|
||||
*/
|
||||
protected $revision;
|
||||
|
||||
/**
|
||||
* The Actor storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $OCActorStorage;
|
||||
|
||||
/**
|
||||
* The date formatter service.
|
||||
*
|
||||
* @var \Drupal\Core\Datetime\DateFormatterInterface
|
||||
*/
|
||||
protected $dateFormatter;
|
||||
|
||||
/**
|
||||
* Constructs a new OCActorRevisionRevertForm.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
|
||||
* The Actor storage.
|
||||
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
|
||||
* The date formatter service.
|
||||
*/
|
||||
public function __construct(EntityStorageInterface $entity_storage, DateFormatterInterface $date_formatter) {
|
||||
$this->OCActorStorage = $entity_storage;
|
||||
$this->dateFormatter = $date_formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager')->getStorage('oc_actor'),
|
||||
$container->get('date.formatter')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'oc_actor_revision_revert_confirm';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return 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_actor.version_history', ['oc_actor' => $this->revision->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return t('Revert');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $oc_actor_revision = NULL) {
|
||||
$this->revision = $this->OCActorStorage->loadRevision($oc_actor_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 = t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]);
|
||||
$this->revision->save();
|
||||
|
||||
$this->logger('content')->notice('Actor: reverted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
|
||||
drupal_set_message(t('Actor %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_actor.version_history',
|
||||
['oc_actor' => $this->revision->id()]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a revision to be reverted.
|
||||
*
|
||||
* @param \Drupal\opencase_entities\Entity\OCActorInterface $revision
|
||||
* The revision to be reverted.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCActorInterface
|
||||
* The prepared revision ready to be stored.
|
||||
*/
|
||||
protected function prepareRevertedRevision(OCActorInterface $revision, FormStateInterface $form_state) {
|
||||
$revision->setNewRevision();
|
||||
$revision->isDefaultRevision(TRUE);
|
||||
$revision->setRevisionCreationTime(REQUEST_TIME);
|
||||
|
||||
return $revision;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Datetime\DateFormatterInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\opencase_entities\Entity\OCActorInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for reverting a Actor revision for a single translation.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActorRevisionRevertTranslationForm extends OCActorRevisionRevertForm {
|
||||
|
||||
|
||||
/**
|
||||
* The language to be reverted.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $langcode;
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* Constructs a new OCActorRevisionRevertTranslationForm.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
|
||||
* The Actor storage.
|
||||
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
|
||||
* The date formatter service.
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
* The language manager.
|
||||
*/
|
||||
public function __construct(EntityStorageInterface $entity_storage, DateFormatterInterface $date_formatter, LanguageManagerInterface $language_manager) {
|
||||
parent::__construct($entity_storage, $date_formatter);
|
||||
$this->languageManager = $language_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager')->getStorage('oc_actor'),
|
||||
$container->get('date.formatter'),
|
||||
$container->get('language_manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'oc_actor_revision_revert_translation_confirm';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return 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_actor_revision = NULL, $langcode = NULL) {
|
||||
$this->langcode = $langcode;
|
||||
$form = parent::buildForm($form, $form_state, $oc_actor_revision);
|
||||
|
||||
$form['revert_untranslated_fields'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Revert content shared among translations'),
|
||||
'#default_value' => FALSE,
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function prepareRevertedRevision(OCActorInterface $revision, FormStateInterface $form_state) {
|
||||
$revert_untranslated_fields = $form_state->getValue('revert_untranslated_fields');
|
||||
|
||||
/** @var \Drupal\opencase_entities\Entity\OCActorInterface $default_revision */
|
||||
$latest_revision = $this->OCActorStorage->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;
|
||||
}
|
||||
|
||||
}
|
53
modules/opencase_entities/src/Form/OCActorSettingsForm.php
Normal file
53
modules/opencase_entities/src/Form/OCActorSettingsForm.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class OCActorSettingsForm.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActorSettingsForm extends FormBase {
|
||||
|
||||
/**
|
||||
* Returns a unique string identifying the form.
|
||||
*
|
||||
* @return string
|
||||
* The unique string identifying the form.
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'ocactor_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 Actor 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['ocactor_settings']['#markup'] = 'Settings form for Actor entities. Manage field settings here.';
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
53
modules/opencase_entities/src/Form/OCActorTypeDeleteForm.php
Normal file
53
modules/opencase_entities/src/Form/OCActorTypeDeleteForm.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?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 Actor type entities.
|
||||
*/
|
||||
class OCActorTypeDeleteForm 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_actor_type.collection');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return $this->t('Delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->entity->delete();
|
||||
|
||||
drupal_set_message(
|
||||
$this->t('content @type: deleted @label.',
|
||||
[
|
||||
'@type' => $this->entity->bundle(),
|
||||
'@label' => $this->entity->label(),
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||
}
|
||||
|
||||
}
|
65
modules/opencase_entities/src/Form/OCActorTypeForm.php
Normal file
65
modules/opencase_entities/src/Form/OCActorTypeForm.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class OCActorTypeForm.
|
||||
*/
|
||||
class OCActorTypeForm extends EntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$form = parent::form($form, $form_state);
|
||||
|
||||
$oc_actor_type = $this->entity;
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Label'),
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => $oc_actor_type->label(),
|
||||
'#description' => $this->t("Label for the Actor type."),
|
||||
'#required' => TRUE,
|
||||
];
|
||||
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#default_value' => $oc_actor_type->id(),
|
||||
'#machine_name' => [
|
||||
'exists' => '\Drupal\opencase_entities\Entity\OCActorType::load',
|
||||
],
|
||||
'#disabled' => !$oc_actor_type->isNew(),
|
||||
];
|
||||
|
||||
/* You will need additional form elements for your custom properties. */
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$oc_actor_type = $this->entity;
|
||||
$status = $oc_actor_type->save();
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
drupal_set_message($this->t('Created the %label Actor type.', [
|
||||
'%label' => $oc_actor_type->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Actor type.', [
|
||||
'%label' => $oc_actor_type->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirectUrl($oc_actor_type->toUrl('collection'));
|
||||
}
|
||||
|
||||
}
|
15
modules/opencase_entities/src/Form/OCCaseDeleteForm.php
Normal file
15
modules/opencase_entities/src/Form/OCCaseDeleteForm.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityDeleteForm;
|
||||
|
||||
/**
|
||||
* Provides a form for deleting Case entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCCaseDeleteForm extends ContentEntityDeleteForm {
|
||||
|
||||
|
||||
}
|
71
modules/opencase_entities/src/Form/OCCaseForm.php
Normal file
71
modules/opencase_entities/src/Form/OCCaseForm.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Form controller for Case edit forms.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCCaseForm extends ContentEntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
/* @var $entity \Drupal\opencase_entities\Entity\OCCase */
|
||||
$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,
|
||||
];
|
||||
}
|
||||
|
||||
$entity = $this->entity;
|
||||
|
||||
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(REQUEST_TIME);
|
||||
$entity->setRevisionUserId(\Drupal::currentUser()->id());
|
||||
}
|
||||
else {
|
||||
$entity->setNewRevision(FALSE);
|
||||
}
|
||||
|
||||
$status = parent::save($form, $form_state);
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
drupal_set_message($this->t('Created the %label Case.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Case.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirect('entity.oc_case.canonical', ['oc_case' => $entity->id()]);
|
||||
}
|
||||
|
||||
}
|
123
modules/opencase_entities/src/Form/OCCaseRevisionDeleteForm.php
Normal file
123
modules/opencase_entities/src/Form/OCCaseRevisionDeleteForm.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
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 Case revision.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCCaseRevisionDeleteForm extends ConfirmFormBase {
|
||||
|
||||
|
||||
/**
|
||||
* The Case revision.
|
||||
*
|
||||
* @var \Drupal\opencase_entities\Entity\OCCaseInterface
|
||||
*/
|
||||
protected $revision;
|
||||
|
||||
/**
|
||||
* The Case storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $OCCaseStorage;
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
* @var \Drupal\Core\Database\Connection
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* Constructs a new OCCaseRevisionDeleteForm.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
|
||||
* The entity storage.
|
||||
* @param \Drupal\Core\Database\Connection $connection
|
||||
* The database connection.
|
||||
*/
|
||||
public function __construct(EntityStorageInterface $entity_storage, Connection $connection) {
|
||||
$this->OCCaseStorage = $entity_storage;
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
$entity_manager = $container->get('entity.manager');
|
||||
return new static(
|
||||
$entity_manager->getStorage('oc_case'),
|
||||
$container->get('database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'oc_case_revision_delete_confirm';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return 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_case.version_history', ['oc_case' => $this->revision->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return t('Delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $oc_case_revision = NULL) {
|
||||
$this->revision = $this->OCCaseStorage->loadRevision($oc_case_revision);
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->OCCaseStorage->deleteRevision($this->revision->getRevisionId());
|
||||
|
||||
$this->logger('content')->notice('Case: deleted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
|
||||
drupal_set_message(t('Revision from %revision-date of Case %title has been deleted.', ['%revision-date' => format_date($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()]));
|
||||
$form_state->setRedirect(
|
||||
'entity.oc_case.canonical',
|
||||
['oc_case' => $this->revision->id()]
|
||||
);
|
||||
if ($this->connection->query('SELECT COUNT(DISTINCT vid) FROM {oc_case_field_revision} WHERE id = :id', [':id' => $this->revision->id()])->fetchField() > 1) {
|
||||
$form_state->setRedirect(
|
||||
'entity.oc_case.version_history',
|
||||
['oc_case' => $this->revision->id()]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
149
modules/opencase_entities/src/Form/OCCaseRevisionRevertForm.php
Normal file
149
modules/opencase_entities/src/Form/OCCaseRevisionRevertForm.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Datetime\DateFormatterInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Form\ConfirmFormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\opencase_entities\Entity\OCCaseInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for reverting a Case revision.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCCaseRevisionRevertForm extends ConfirmFormBase {
|
||||
|
||||
|
||||
/**
|
||||
* The Case revision.
|
||||
*
|
||||
* @var \Drupal\opencase_entities\Entity\OCCaseInterface
|
||||
*/
|
||||
protected $revision;
|
||||
|
||||
/**
|
||||
* The Case storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $OCCaseStorage;
|
||||
|
||||
/**
|
||||
* The date formatter service.
|
||||
*
|
||||
* @var \Drupal\Core\Datetime\DateFormatterInterface
|
||||
*/
|
||||
protected $dateFormatter;
|
||||
|
||||
/**
|
||||
* Constructs a new OCCaseRevisionRevertForm.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
|
||||
* The Case storage.
|
||||
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
|
||||
* The date formatter service.
|
||||
*/
|
||||
public function __construct(EntityStorageInterface $entity_storage, DateFormatterInterface $date_formatter) {
|
||||
$this->OCCaseStorage = $entity_storage;
|
||||
$this->dateFormatter = $date_formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager')->getStorage('oc_case'),
|
||||
$container->get('date.formatter')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'oc_case_revision_revert_confirm';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return 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_case.version_history', ['oc_case' => $this->revision->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return t('Revert');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $oc_case_revision = NULL) {
|
||||
$this->revision = $this->OCCaseStorage->loadRevision($oc_case_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 = t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]);
|
||||
$this->revision->save();
|
||||
|
||||
$this->logger('content')->notice('Case: reverted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
|
||||
drupal_set_message(t('Case %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_case.version_history',
|
||||
['oc_case' => $this->revision->id()]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a revision to be reverted.
|
||||
*
|
||||
* @param \Drupal\opencase_entities\Entity\OCCaseInterface $revision
|
||||
* The revision to be reverted.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*
|
||||
* @return \Drupal\opencase_entities\Entity\OCCaseInterface
|
||||
* The prepared revision ready to be stored.
|
||||
*/
|
||||
protected function prepareRevertedRevision(OCCaseInterface $revision, FormStateInterface $form_state) {
|
||||
$revision->setNewRevision();
|
||||
$revision->isDefaultRevision(TRUE);
|
||||
$revision->setRevisionCreationTime(REQUEST_TIME);
|
||||
|
||||
return $revision;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Datetime\DateFormatterInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\opencase_entities\Entity\OCCaseInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for reverting a Case revision for a single translation.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCCaseRevisionRevertTranslationForm extends OCCaseRevisionRevertForm {
|
||||
|
||||
|
||||
/**
|
||||
* The language to be reverted.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $langcode;
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* Constructs a new OCCaseRevisionRevertTranslationForm.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
|
||||
* The Case storage.
|
||||
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
|
||||
* The date formatter service.
|
||||
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
|
||||
* The language manager.
|
||||
*/
|
||||
public function __construct(EntityStorageInterface $entity_storage, DateFormatterInterface $date_formatter, LanguageManagerInterface $language_manager) {
|
||||
parent::__construct($entity_storage, $date_formatter);
|
||||
$this->languageManager = $language_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager')->getStorage('oc_case'),
|
||||
$container->get('date.formatter'),
|
||||
$container->get('language_manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'oc_case_revision_revert_translation_confirm';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return 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_case_revision = NULL, $langcode = NULL) {
|
||||
$this->langcode = $langcode;
|
||||
$form = parent::buildForm($form, $form_state, $oc_case_revision);
|
||||
|
||||
$form['revert_untranslated_fields'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Revert content shared among translations'),
|
||||
'#default_value' => FALSE,
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function prepareRevertedRevision(OCCaseInterface $revision, FormStateInterface $form_state) {
|
||||
$revert_untranslated_fields = $form_state->getValue('revert_untranslated_fields');
|
||||
|
||||
/** @var \Drupal\opencase_entities\Entity\OCCaseInterface $default_revision */
|
||||
$latest_revision = $this->OCCaseStorage->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;
|
||||
}
|
||||
|
||||
}
|
53
modules/opencase_entities/src/Form/OCCaseSettingsForm.php
Normal file
53
modules/opencase_entities/src/Form/OCCaseSettingsForm.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class OCCaseSettingsForm.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCCaseSettingsForm extends FormBase {
|
||||
|
||||
/**
|
||||
* Returns a unique string identifying the form.
|
||||
*
|
||||
* @return string
|
||||
* The unique string identifying the form.
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'occase_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 Case 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['occase_settings']['#markup'] = 'Settings form for Case entities. Manage field settings here.';
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
53
modules/opencase_entities/src/Form/OCCaseTypeDeleteForm.php
Normal file
53
modules/opencase_entities/src/Form/OCCaseTypeDeleteForm.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?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 Case type entities.
|
||||
*/
|
||||
class OCCaseTypeDeleteForm 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_case_type.collection');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return $this->t('Delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->entity->delete();
|
||||
|
||||
drupal_set_message(
|
||||
$this->t('content @type: deleted @label.',
|
||||
[
|
||||
'@type' => $this->entity->bundle(),
|
||||
'@label' => $this->entity->label(),
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||
}
|
||||
|
||||
}
|
65
modules/opencase_entities/src/Form/OCCaseTypeForm.php
Normal file
65
modules/opencase_entities/src/Form/OCCaseTypeForm.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class OCCaseTypeForm.
|
||||
*/
|
||||
class OCCaseTypeForm extends EntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$form = parent::form($form, $form_state);
|
||||
|
||||
$oc_case_type = $this->entity;
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Label'),
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => $oc_case_type->label(),
|
||||
'#description' => $this->t("Label for the Case type."),
|
||||
'#required' => TRUE,
|
||||
];
|
||||
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#default_value' => $oc_case_type->id(),
|
||||
'#machine_name' => [
|
||||
'exists' => '\Drupal\opencase_entities\Entity\OCCaseType::load',
|
||||
],
|
||||
'#disabled' => !$oc_case_type->isNew(),
|
||||
];
|
||||
|
||||
/* You will need additional form elements for your custom properties. */
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$oc_case_type = $this->entity;
|
||||
$status = $oc_case_type->save();
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
drupal_set_message($this->t('Created the %label Case type.', [
|
||||
'%label' => $oc_case_type->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Case type.', [
|
||||
'%label' => $oc_case_type->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirectUrl($oc_case_type->toUrl('collection'));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?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 Activity entity.
|
||||
*
|
||||
* @see \Drupal\opencase_entities\Entity\OCActivity.
|
||||
*/
|
||||
class OCActivityAccessControlHandler extends EntityAccessControlHandler {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
/** @var \Drupal\opencase_entities\Entity\OCActivityInterface $entity */
|
||||
switch ($operation) {
|
||||
case 'view':
|
||||
if (!$entity->isPublished()) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'view unpublished activity entities');
|
||||
}
|
||||
return AccessResult::allowedIfHasPermission($account, 'view published activity entities');
|
||||
|
||||
case 'update':
|
||||
return AccessResult::allowedIfHasPermission($account, 'edit activity entities');
|
||||
|
||||
case 'delete':
|
||||
return AccessResult::allowedIfHasPermission($account, 'delete activity entities');
|
||||
}
|
||||
|
||||
// Unknown operation, no opinion.
|
||||
return AccessResult::neutral();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'add activity entities');
|
||||
}
|
||||
|
||||
}
|
196
modules/opencase_entities/src/OCActivityHtmlRouteProvider.php
Normal file
196
modules/opencase_entities/src/OCActivityHtmlRouteProvider.php
Normal file
@ -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 Activity entities.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class OCActivityHtmlRouteProvider 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\OCActivityController::revisionOverview',
|
||||
])
|
||||
->setRequirement('_permission', 'access activity 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\OCActivityController::revisionShow',
|
||||
'_title_callback' => '\Drupal\opencase_entities\Controller\OCActivityController::revisionPageTitle',
|
||||
])
|
||||
->setRequirement('_permission', 'access activity 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\OCActivityRevisionRevertForm',
|
||||
'_title' => 'Revert to earlier revision',
|
||||
])
|
||||
->setRequirement('_permission', 'revert all activity 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\OCActivityRevisionDeleteForm',
|
||||
'_title' => 'Delete earlier revision',
|
||||
])
|
||||
->setRequirement('_permission', 'delete all activity 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\OCActivityRevisionRevertTranslationForm',
|
||||
'_title' => 'Revert to earlier revision of a translation',
|
||||
])
|
||||
->setRequirement('_permission', 'revert all activity 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\OCActivitySettingsForm',
|
||||
'_title' => "{$entity_type->getLabel()} settings",
|
||||
])
|
||||
->setRequirement('_permission', $entity_type->getAdminPermission())
|
||||
->setOption('_admin_route', TRUE);
|
||||
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
40
modules/opencase_entities/src/OCActivityListBuilder.php
Normal file
40
modules/opencase_entities/src/OCActivityListBuilder.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?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 Activity entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActivityListBuilder extends EntityListBuilder {
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['id'] = $this->t('Activity ID');
|
||||
$header['name'] = $this->t('Name');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
/* @var $entity \Drupal\opencase_entities\Entity\OCActivity */
|
||||
$row['id'] = $entity->id();
|
||||
$row['name'] = Link::createFromRoute(
|
||||
$entity->label(),
|
||||
'entity.oc_activity.edit_form',
|
||||
['oc_activity' => $entity->id()]
|
||||
);
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
}
|
58
modules/opencase_entities/src/OCActivityStorage.php
Normal file
58
modules/opencase_entities/src/OCActivityStorage.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\OCActivityInterface;
|
||||
|
||||
/**
|
||||
* Defines the storage handler class for Activity entities.
|
||||
*
|
||||
* This extends the base storage class, adding required special handling for
|
||||
* Activity entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActivityStorage extends SqlContentEntityStorage implements OCActivityStorageInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function revisionIds(OCActivityInterface $entity) {
|
||||
return $this->database->query(
|
||||
'SELECT vid FROM {oc_activity_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_activity_field_revision} WHERE uid = :uid ORDER BY vid',
|
||||
[':uid' => $account->id()]
|
||||
)->fetchCol();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function countDefaultLanguageRevisions(OCActivityInterface $entity) {
|
||||
return $this->database->query('SELECT COUNT(*) FROM {oc_activity_field_revision} WHERE id = :id AND default_langcode = 1', [':id' => $entity->id()])
|
||||
->fetchField();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearRevisionsLanguage(LanguageInterface $language) {
|
||||
return $this->database->update('oc_activity_revision')
|
||||
->fields(['langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED])
|
||||
->condition('langcode', $language->getId())
|
||||
->execute();
|
||||
}
|
||||
|
||||
}
|
61
modules/opencase_entities/src/OCActivityStorageInterface.php
Normal file
61
modules/opencase_entities/src/OCActivityStorageInterface.php
Normal file
@ -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\OCActivityInterface;
|
||||
|
||||
/**
|
||||
* Defines the storage handler class for Activity entities.
|
||||
*
|
||||
* This extends the base storage class, adding required special handling for
|
||||
* Activity entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
interface OCActivityStorageInterface extends ContentEntityStorageInterface {
|
||||
|
||||
/**
|
||||
* Gets a list of Activity revision IDs for a specific Activity.
|
||||
*
|
||||
* @param \Drupal\opencase_entities\Entity\OCActivityInterface $entity
|
||||
* The Activity entity.
|
||||
*
|
||||
* @return int[]
|
||||
* Activity revision IDs (in ascending order).
|
||||
*/
|
||||
public function revisionIds(OCActivityInterface $entity);
|
||||
|
||||
/**
|
||||
* Gets a list of revision IDs having a given user as Activity author.
|
||||
*
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* The user entity.
|
||||
*
|
||||
* @return int[]
|
||||
* Activity revision IDs (in ascending order).
|
||||
*/
|
||||
public function userRevisionIds(AccountInterface $account);
|
||||
|
||||
/**
|
||||
* Counts the number of revisions in the default language.
|
||||
*
|
||||
* @param \Drupal\opencase_entities\Entity\OCActivityInterface $entity
|
||||
* The Activity entity.
|
||||
*
|
||||
* @return int
|
||||
* The number of revisions in the default language.
|
||||
*/
|
||||
public function countDefaultLanguageRevisions(OCActivityInterface $entity);
|
||||
|
||||
/**
|
||||
* Unsets the language for all Activity with the given language.
|
||||
*
|
||||
* @param \Drupal\Core\Language\LanguageInterface $language
|
||||
* The language object.
|
||||
*/
|
||||
public function clearRevisionsLanguage(LanguageInterface $language);
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities;
|
||||
|
||||
use Drupal\content_translation\ContentTranslationHandler;
|
||||
|
||||
/**
|
||||
* Defines the translation handler for oc_activity.
|
||||
*/
|
||||
class OCActivityTranslationHandler extends ContentTranslationHandler {
|
||||
|
||||
// Override here the needed methods from ContentTranslationHandler.
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Provides routes for Activity type entities.
|
||||
*
|
||||
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class OCActivityTypeHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutes(EntityTypeInterface $entity_type) {
|
||||
$collection = parent::getRoutes($entity_type);
|
||||
|
||||
// Provide your custom entity routes here.
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
}
|
32
modules/opencase_entities/src/OCActivityTypeListBuilder.php
Normal file
32
modules/opencase_entities/src/OCActivityTypeListBuilder.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Provides a listing of Activity type entities.
|
||||
*/
|
||||
class OCActivityTypeListBuilder extends ConfigEntityListBuilder {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['label'] = $this->t('Activity 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,47 @@
|
||||
<?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 Actor entity.
|
||||
*
|
||||
* @see \Drupal\opencase_entities\Entity\OCActor.
|
||||
*/
|
||||
class OCActorAccessControlHandler extends EntityAccessControlHandler {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
/** @var \Drupal\opencase_entities\Entity\OCActorInterface $entity */
|
||||
switch ($operation) {
|
||||
case 'view':
|
||||
if (!$entity->isPublished()) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'view unpublished actor entities');
|
||||
}
|
||||
return AccessResult::allowedIfHasPermission($account, 'view published actor entities');
|
||||
|
||||
case 'update':
|
||||
return AccessResult::allowedIfHasPermission($account, 'edit actor entities');
|
||||
|
||||
case 'delete':
|
||||
return AccessResult::allowedIfHasPermission($account, 'delete actor entities');
|
||||
}
|
||||
|
||||
// Unknown operation, no opinion.
|
||||
return AccessResult::neutral();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'add actor entities');
|
||||
}
|
||||
|
||||
}
|
196
modules/opencase_entities/src/OCActorHtmlRouteProvider.php
Normal file
196
modules/opencase_entities/src/OCActorHtmlRouteProvider.php
Normal file
@ -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 Actor entities.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class OCActorHtmlRouteProvider 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\OCActorController::revisionOverview',
|
||||
])
|
||||
->setRequirement('_permission', 'access actor 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\OCActorController::revisionShow',
|
||||
'_title_callback' => '\Drupal\opencase_entities\Controller\OCActorController::revisionPageTitle',
|
||||
])
|
||||
->setRequirement('_permission', 'access actor 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\OCActorRevisionRevertForm',
|
||||
'_title' => 'Revert to earlier revision',
|
||||
])
|
||||
->setRequirement('_permission', 'revert all actor 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\OCActorRevisionDeleteForm',
|
||||
'_title' => 'Delete earlier revision',
|
||||
])
|
||||
->setRequirement('_permission', 'delete all actor 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\OCActorRevisionRevertTranslationForm',
|
||||
'_title' => 'Revert to earlier revision of a translation',
|
||||
])
|
||||
->setRequirement('_permission', 'revert all actor 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\OCActorSettingsForm',
|
||||
'_title' => "{$entity_type->getLabel()} settings",
|
||||
])
|
||||
->setRequirement('_permission', $entity_type->getAdminPermission())
|
||||
->setOption('_admin_route', TRUE);
|
||||
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
40
modules/opencase_entities/src/OCActorListBuilder.php
Normal file
40
modules/opencase_entities/src/OCActorListBuilder.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?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 Actor entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActorListBuilder extends EntityListBuilder {
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['id'] = $this->t('Actor ID');
|
||||
$header['name'] = $this->t('Name');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
/* @var $entity \Drupal\opencase_entities\Entity\OCActor */
|
||||
$row['id'] = $entity->id();
|
||||
$row['name'] = Link::createFromRoute(
|
||||
$entity->label(),
|
||||
'entity.oc_actor.edit_form',
|
||||
['oc_actor' => $entity->id()]
|
||||
);
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
}
|
58
modules/opencase_entities/src/OCActorStorage.php
Normal file
58
modules/opencase_entities/src/OCActorStorage.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\OCActorInterface;
|
||||
|
||||
/**
|
||||
* Defines the storage handler class for Actor entities.
|
||||
*
|
||||
* This extends the base storage class, adding required special handling for
|
||||
* Actor entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCActorStorage extends SqlContentEntityStorage implements OCActorStorageInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function revisionIds(OCActorInterface $entity) {
|
||||
return $this->database->query(
|
||||
'SELECT vid FROM {oc_actor_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_actor_field_revision} WHERE uid = :uid ORDER BY vid',
|
||||
[':uid' => $account->id()]
|
||||
)->fetchCol();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function countDefaultLanguageRevisions(OCActorInterface $entity) {
|
||||
return $this->database->query('SELECT COUNT(*) FROM {oc_actor_field_revision} WHERE id = :id AND default_langcode = 1', [':id' => $entity->id()])
|
||||
->fetchField();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearRevisionsLanguage(LanguageInterface $language) {
|
||||
return $this->database->update('oc_actor_revision')
|
||||
->fields(['langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED])
|
||||
->condition('langcode', $language->getId())
|
||||
->execute();
|
||||
}
|
||||
|
||||
}
|
61
modules/opencase_entities/src/OCActorStorageInterface.php
Normal file
61
modules/opencase_entities/src/OCActorStorageInterface.php
Normal file
@ -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\OCActorInterface;
|
||||
|
||||
/**
|
||||
* Defines the storage handler class for Actor entities.
|
||||
*
|
||||
* This extends the base storage class, adding required special handling for
|
||||
* Actor entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
interface OCActorStorageInterface extends ContentEntityStorageInterface {
|
||||
|
||||
/**
|
||||
* Gets a list of Actor revision IDs for a specific Actor.
|
||||
*
|
||||
* @param \Drupal\opencase_entities\Entity\OCActorInterface $entity
|
||||
* The Actor entity.
|
||||
*
|
||||
* @return int[]
|
||||
* Actor revision IDs (in ascending order).
|
||||
*/
|
||||
public function revisionIds(OCActorInterface $entity);
|
||||
|
||||
/**
|
||||
* Gets a list of revision IDs having a given user as Actor author.
|
||||
*
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* The user entity.
|
||||
*
|
||||
* @return int[]
|
||||
* Actor revision IDs (in ascending order).
|
||||
*/
|
||||
public function userRevisionIds(AccountInterface $account);
|
||||
|
||||
/**
|
||||
* Counts the number of revisions in the default language.
|
||||
*
|
||||
* @param \Drupal\opencase_entities\Entity\OCActorInterface $entity
|
||||
* The Actor entity.
|
||||
*
|
||||
* @return int
|
||||
* The number of revisions in the default language.
|
||||
*/
|
||||
public function countDefaultLanguageRevisions(OCActorInterface $entity);
|
||||
|
||||
/**
|
||||
* Unsets the language for all Actor with the given language.
|
||||
*
|
||||
* @param \Drupal\Core\Language\LanguageInterface $language
|
||||
* The language object.
|
||||
*/
|
||||
public function clearRevisionsLanguage(LanguageInterface $language);
|
||||
|
||||
}
|
14
modules/opencase_entities/src/OCActorTranslationHandler.php
Normal file
14
modules/opencase_entities/src/OCActorTranslationHandler.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities;
|
||||
|
||||
use Drupal\content_translation\ContentTranslationHandler;
|
||||
|
||||
/**
|
||||
* Defines the translation handler for oc_actor.
|
||||
*/
|
||||
class OCActorTranslationHandler extends ContentTranslationHandler {
|
||||
|
||||
// Override here the needed methods from ContentTranslationHandler.
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Provides routes for Actor type entities.
|
||||
*
|
||||
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class OCActorTypeHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutes(EntityTypeInterface $entity_type) {
|
||||
$collection = parent::getRoutes($entity_type);
|
||||
|
||||
// Provide your custom entity routes here.
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
}
|
32
modules/opencase_entities/src/OCActorTypeListBuilder.php
Normal file
32
modules/opencase_entities/src/OCActorTypeListBuilder.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Provides a listing of Actor type entities.
|
||||
*/
|
||||
class OCActorTypeListBuilder extends ConfigEntityListBuilder {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['label'] = $this->t('Actor 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);
|
||||
}
|
||||
|
||||
}
|
47
modules/opencase_entities/src/OCCaseAccessControlHandler.php
Normal file
47
modules/opencase_entities/src/OCCaseAccessControlHandler.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?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 Case entity.
|
||||
*
|
||||
* @see \Drupal\opencase_entities\Entity\OCCase.
|
||||
*/
|
||||
class OCCaseAccessControlHandler extends EntityAccessControlHandler {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
/** @var \Drupal\opencase_entities\Entity\OCCaseInterface $entity */
|
||||
switch ($operation) {
|
||||
case 'view':
|
||||
if (!$entity->isPublished()) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'view unpublished case entities');
|
||||
}
|
||||
return AccessResult::allowedIfHasPermission($account, 'view published case entities');
|
||||
|
||||
case 'update':
|
||||
return AccessResult::allowedIfHasPermission($account, 'edit case entities');
|
||||
|
||||
case 'delete':
|
||||
return AccessResult::allowedIfHasPermission($account, 'delete case entities');
|
||||
}
|
||||
|
||||
// Unknown operation, no opinion.
|
||||
return AccessResult::neutral();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'add case entities');
|
||||
}
|
||||
|
||||
}
|
196
modules/opencase_entities/src/OCCaseHtmlRouteProvider.php
Normal file
196
modules/opencase_entities/src/OCCaseHtmlRouteProvider.php
Normal file
@ -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 Case entities.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class OCCaseHtmlRouteProvider 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\OCCaseController::revisionOverview',
|
||||
])
|
||||
->setRequirement('_permission', 'access case 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\OCCaseController::revisionShow',
|
||||
'_title_callback' => '\Drupal\opencase_entities\Controller\OCCaseController::revisionPageTitle',
|
||||
])
|
||||
->setRequirement('_permission', 'access case 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\OCCaseRevisionRevertForm',
|
||||
'_title' => 'Revert to earlier revision',
|
||||
])
|
||||
->setRequirement('_permission', 'revert all case 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\OCCaseRevisionDeleteForm',
|
||||
'_title' => 'Delete earlier revision',
|
||||
])
|
||||
->setRequirement('_permission', 'delete all case 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\OCCaseRevisionRevertTranslationForm',
|
||||
'_title' => 'Revert to earlier revision of a translation',
|
||||
])
|
||||
->setRequirement('_permission', 'revert all case 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\OCCaseSettingsForm',
|
||||
'_title' => "{$entity_type->getLabel()} settings",
|
||||
])
|
||||
->setRequirement('_permission', $entity_type->getAdminPermission())
|
||||
->setOption('_admin_route', TRUE);
|
||||
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
40
modules/opencase_entities/src/OCCaseListBuilder.php
Normal file
40
modules/opencase_entities/src/OCCaseListBuilder.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?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 Case entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCCaseListBuilder extends EntityListBuilder {
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['id'] = $this->t('Case ID');
|
||||
$header['name'] = $this->t('Name');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
/* @var $entity \Drupal\opencase_entities\Entity\OCCase */
|
||||
$row['id'] = $entity->id();
|
||||
$row['name'] = Link::createFromRoute(
|
||||
$entity->label(),
|
||||
'entity.oc_case.edit_form',
|
||||
['oc_case' => $entity->id()]
|
||||
);
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
}
|
58
modules/opencase_entities/src/OCCaseStorage.php
Normal file
58
modules/opencase_entities/src/OCCaseStorage.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\OCCaseInterface;
|
||||
|
||||
/**
|
||||
* Defines the storage handler class for Case entities.
|
||||
*
|
||||
* This extends the base storage class, adding required special handling for
|
||||
* Case entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
class OCCaseStorage extends SqlContentEntityStorage implements OCCaseStorageInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function revisionIds(OCCaseInterface $entity) {
|
||||
return $this->database->query(
|
||||
'SELECT vid FROM {oc_case_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_case_field_revision} WHERE uid = :uid ORDER BY vid',
|
||||
[':uid' => $account->id()]
|
||||
)->fetchCol();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function countDefaultLanguageRevisions(OCCaseInterface $entity) {
|
||||
return $this->database->query('SELECT COUNT(*) FROM {oc_case_field_revision} WHERE id = :id AND default_langcode = 1', [':id' => $entity->id()])
|
||||
->fetchField();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearRevisionsLanguage(LanguageInterface $language) {
|
||||
return $this->database->update('oc_case_revision')
|
||||
->fields(['langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED])
|
||||
->condition('langcode', $language->getId())
|
||||
->execute();
|
||||
}
|
||||
|
||||
}
|
61
modules/opencase_entities/src/OCCaseStorageInterface.php
Normal file
61
modules/opencase_entities/src/OCCaseStorageInterface.php
Normal file
@ -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\OCCaseInterface;
|
||||
|
||||
/**
|
||||
* Defines the storage handler class for Case entities.
|
||||
*
|
||||
* This extends the base storage class, adding required special handling for
|
||||
* Case entities.
|
||||
*
|
||||
* @ingroup opencase_entities
|
||||
*/
|
||||
interface OCCaseStorageInterface extends ContentEntityStorageInterface {
|
||||
|
||||
/**
|
||||
* Gets a list of Case revision IDs for a specific Case.
|
||||
*
|
||||
* @param \Drupal\opencase_entities\Entity\OCCaseInterface $entity
|
||||
* The Case entity.
|
||||
*
|
||||
* @return int[]
|
||||
* Case revision IDs (in ascending order).
|
||||
*/
|
||||
public function revisionIds(OCCaseInterface $entity);
|
||||
|
||||
/**
|
||||
* Gets a list of revision IDs having a given user as Case author.
|
||||
*
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* The user entity.
|
||||
*
|
||||
* @return int[]
|
||||
* Case revision IDs (in ascending order).
|
||||
*/
|
||||
public function userRevisionIds(AccountInterface $account);
|
||||
|
||||
/**
|
||||
* Counts the number of revisions in the default language.
|
||||
*
|
||||
* @param \Drupal\opencase_entities\Entity\OCCaseInterface $entity
|
||||
* The Case entity.
|
||||
*
|
||||
* @return int
|
||||
* The number of revisions in the default language.
|
||||
*/
|
||||
public function countDefaultLanguageRevisions(OCCaseInterface $entity);
|
||||
|
||||
/**
|
||||
* Unsets the language for all Case with the given language.
|
||||
*
|
||||
* @param \Drupal\Core\Language\LanguageInterface $language
|
||||
* The language object.
|
||||
*/
|
||||
public function clearRevisionsLanguage(LanguageInterface $language);
|
||||
|
||||
}
|
14
modules/opencase_entities/src/OCCaseTranslationHandler.php
Normal file
14
modules/opencase_entities/src/OCCaseTranslationHandler.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities;
|
||||
|
||||
use Drupal\content_translation\ContentTranslationHandler;
|
||||
|
||||
/**
|
||||
* Defines the translation handler for oc_case.
|
||||
*/
|
||||
class OCCaseTranslationHandler extends ContentTranslationHandler {
|
||||
|
||||
// Override here the needed methods from ContentTranslationHandler.
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Provides routes for Case type entities.
|
||||
*
|
||||
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class OCCaseTypeHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutes(EntityTypeInterface $entity_type) {
|
||||
$collection = parent::getRoutes($entity_type);
|
||||
|
||||
// Provide your custom entity routes here.
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
}
|
32
modules/opencase_entities/src/OCCaseTypeListBuilder.php
Normal file
32
modules/opencase_entities/src/OCCaseTypeListBuilder.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase_entities;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Provides a listing of Case type entities.
|
||||
*/
|
||||
class OCCaseTypeListBuilder extends ConfigEntityListBuilder {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['label'] = $this->t('Case 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_activity_content_add_list()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
{% spaceless %}
|
||||
<dl>
|
||||
{% for type in types %}
|
||||
<dt>{{ type.link }}</dt>
|
||||
{% endfor %}
|
||||
</dl>
|
||||
{% endspaceless %}
|
@ -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_actor_content_add_list()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
{% spaceless %}
|
||||
<dl>
|
||||
{% for type in types %}
|
||||
<dt>{{ type.link }}</dt>
|
||||
{% endfor %}
|
||||
</dl>
|
||||
{% endspaceless %}
|
@ -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_case_content_add_list()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
{% spaceless %}
|
||||
<dl>
|
||||
{% for type in types %}
|
||||
<dt>{{ type.link }}</dt>
|
||||
{% endfor %}
|
||||
</dl>
|
||||
{% endspaceless %}
|
22
modules/opencase_entities/templates/oc_activity.html.twig
Normal file
22
modules/opencase_entities/templates/oc_activity.html.twig
Normal file
@ -0,0 +1,22 @@
|
||||
{#
|
||||
/**
|
||||
* @file oc_activity.html.twig
|
||||
* Default theme implementation to present Activity data.
|
||||
*
|
||||
* This template is used when viewing Activity 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_activity()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
<div{{ attributes.addClass('oc_activity') }}>
|
||||
{% if content %}
|
||||
{{- content -}}
|
||||
{% endif %}
|
||||
</div>
|
22
modules/opencase_entities/templates/oc_actor.html.twig
Normal file
22
modules/opencase_entities/templates/oc_actor.html.twig
Normal file
@ -0,0 +1,22 @@
|
||||
{#
|
||||
/**
|
||||
* @file oc_actor.html.twig
|
||||
* Default theme implementation to present Actor data.
|
||||
*
|
||||
* This template is used when viewing Actor 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_actor()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
<div{{ attributes.addClass('oc_actor') }}>
|
||||
{% if content %}
|
||||
{{- content -}}
|
||||
{% endif %}
|
||||
</div>
|
22
modules/opencase_entities/templates/oc_case.html.twig
Normal file
22
modules/opencase_entities/templates/oc_case.html.twig
Normal file
@ -0,0 +1,22 @@
|
||||
{#
|
||||
/**
|
||||
* @file oc_case.html.twig
|
||||
* Default theme implementation to present Case data.
|
||||
*
|
||||
* This template is used when viewing Case 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_case()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
<div{{ attributes.addClass('oc_case') }}>
|
||||
{% if content %}
|
||||
{{- content -}}
|
||||
{% endif %}
|
||||
</div>
|
Reference in New Issue
Block a user