Commit 5ca83549 authored by Achilles's avatar Achilles

modified eiek entitychanger

parent 59e25b62
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -4,5 +4,4 @@ description: My Entities module
core: 8.x
package: Custom
dependencies:
- datetime
- telephone
- rest
\ No newline at end of file
File mode changed from 100644 to 100755
......@@ -14,11 +14,6 @@ entity.student_entity.edit_form:
base_route: entity.student_entity.canonical
title: 'Edit'
entity.student_entity.version_history:
route_name: entity.student_entity.version_history
base_route: entity.student_entity.canonical
title: 'Revisions'
entity.student_entity.delete_form:
route_name: entity.student_entity.delete_form
base_route: entity.student_entity.canonical
......@@ -42,11 +37,6 @@ entity.eidikotita_entity.edit_form:
base_route: entity.eidikotita_entity.canonical
title: 'Edit'
entity.eidikotita_entity.version_history:
route_name: entity.eidikotita_entity.version_history
base_route: entity.eidikotita_entity.canonical
title: 'Revisions'
entity.eidikotita_entity.delete_form:
route_name: entity.eidikotita_entity.delete_form
base_route: entity.eidikotita_entity.canonical
......@@ -124,3 +114,4 @@ entity.school_entity.delete_form:
title: Delete
weight: 10
......@@ -21,52 +21,9 @@ view published student entity entities:
view unpublished student entity entities:
title: 'View unpublished Student entity entities'
view all student entity revisions:
title: 'View all Student entity revisions'
revert all student entity revisions:
title: 'Revert all Student entity revisions'
description: 'Role requires permission <em>view Student entity revisions</em> and <em>edit rights</em> for student entity entities in question or <em>administer student entity entities</em>.'
delete all student entity revisions:
title: 'Delete all revisions'
description: 'Role requires permission to <em>view Student entity revisions</em> and <em>delete rights</em> for student entity entities in question or <em>administer student entity entities</em>.'
add request entity entities:
title: 'Create new Request entity entities'
administer request entity entities:
title: 'Administer Request entity entities'
description: 'Allow to access the administration form to configure Request entity entities.'
restrict access: true
delete request entity entities:
title: 'Delete Request entity entities'
edit request entity entities:
title: 'Edit Request entity entities'
access request entity overview:
title: 'Access the Request entity overview page'
view published request entity entities:
title: 'View published Request entity entities'
view unpublished request entity entities:
title: 'View unpublished Request entity entities'
view all request entity revisions:
title: 'View all Request entity revisions'
revert all request entity revisions:
title: 'Revert all Request entity revisions'
description: 'Role requires permission <em>view Request entity revisions</em> and <em>edit rights</em> for request entity entities in question or <em>administer request entity entities</em>.'
delete all request entity revisions:
title: 'Delete all revisions'
description: 'Role requires permission to <em>view Request entity revisions</em> and <em>delete rights</em> for request entity entities in question or <em>administer request entity entities</em>.'
add eidikotita entity entities:
title: 'Create new Eidikotita entity entities'
administer eidikotita entity entities:
title: 'Administer Eidikotita entity entities'
description: 'Allow to access the administration form to configure Eidikotita entity entities.'
......@@ -87,19 +44,6 @@ view published eidikotita entity entities:
view unpublished eidikotita entity entities:
title: 'View unpublished Eidikotita entity entities'
view all eidikotita entity revisions:
title: 'View all Eidikotita entity revisions'
revert all eidikotita entity revisions:
title: 'Revert all Eidikotita entity revisions'
description: 'Role requires permission <em>view Eidikotita entity revisions</em> and <em>edit rights</em> for eidikotita entity entities in question or <em>administer eidikotita entity entities</em>.'
delete all eidikotita entity revisions:
title: 'Delete all revisions'
description: 'Role requires permission to <em>view Eidikotita entity revisions</em> and <em>delete rights</em> for eidikotita entity entities in question or <em>administer eidikotita entity entities</em>.'
add aitisi entity entities:
title: 'Create new Aitisi entity entities'
administer aitisi entity entities:
title: 'Administer Aitisi entity entities'
description: 'Allow to access the administration form to configure Aitisi entity entities.'
......@@ -174,3 +118,5 @@ view published school entity entities:
view unpublished school entity entities:
title: 'View unpublished School entity entities'
add test entity entities:
title: 'Create new Test entity entities'
\ No newline at end of file
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
<?php
namespace Drupal\eiek\Controller;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Url;
use Drupal\eiek\Entity\EidikotitaEntityInterface;
/**
* Class EidikotitaEntityController.
*
* Returns responses for Eidikotita entity routes.
*
* @package Drupal\eiek\Controller
*/
class EidikotitaEntityController extends ControllerBase implements ContainerInjectionInterface {
/**
* Displays a Eidikotita entity revision.
*
* @param int $eidikotita_entity_revision
* The Eidikotita entity revision ID.
*
* @return array
* An array suitable for drupal_render().
*/
public function revisionShow($eidikotita_entity_revision) {
$eidikotita_entity = $this->entityManager()->getStorage('eidikotita_entity')->loadRevision($eidikotita_entity_revision);
$view_builder = $this->entityManager()->getViewBuilder('eidikotita_entity');
return $view_builder->view($eidikotita_entity);
}
/**
* Page title callback for a Eidikotita entity revision.
*
* @param int $eidikotita_entity_revision
* The Eidikotita entity revision ID.
*
* @return string
* The page title.
*/
public function revisionPageTitle($eidikotita_entity_revision) {
$eidikotita_entity = $this->entityManager()->getStorage('eidikotita_entity')->loadRevision($eidikotita_entity_revision);
return $this->t('Revision of %title from %date', array('%title' => $eidikotita_entity->label(), '%date' => format_date($eidikotita_entity->getRevisionCreationTime())));
}
/**
* Generates an overview table of older revisions of a Eidikotita entity .
*
* @param \Drupal\eiek\Entity\EidikotitaEntityInterface $eidikotita_entity
* A Eidikotita entity object.
*
* @return array
* An array as expected by drupal_render().
*/
public function revisionOverview(EidikotitaEntityInterface $eidikotita_entity) {
$account = $this->currentUser();
$langcode = $eidikotita_entity->language()->getId();
$langname = $eidikotita_entity->language()->getName();
$languages = $eidikotita_entity->getTranslationLanguages();
$has_translations = (count($languages) > 1);
$eidikotita_entity_storage = $this->entityManager()->getStorage('eidikotita_entity');
$build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => $eidikotita_entity->label()]) : $this->t('Revisions for %title', ['%title' => $eidikotita_entity->label()]);
$header = array($this->t('Revision'), $this->t('Operations'));
$revert_permission = (($account->hasPermission("revert all eidikotita entity revisions") || $account->hasPermission('administer eidikotita entity entities')));
$delete_permission = (($account->hasPermission("delete all eidikotita entity revisions") || $account->hasPermission('administer eidikotita entity entities')));
$rows = array();
$vids = $eidikotita_entity_storage->revisionIds($eidikotita_entity);
$latest_revision = TRUE;
foreach (array_reverse($vids) as $vid) {
/** @var \Drupal\eiek\EidikotitaEntityInterface $revision */
$revision = $eidikotita_entity_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->revision_timestamp->value, 'short');
if ($vid != $eidikotita_entity->getRevisionId()) {
$link = $this->l($date, new Url('entity.eidikotita_entity.revision', ['eidikotita_entity' => $eidikotita_entity->id(), 'eidikotita_entity_revision' => $vid]));
}
else {
$link = $eidikotita_entity->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->revision_log_message->value, '#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' => Url::fromRoute('eidikotita_entity.revision_revert_confirm', ['eidikotita_entity' => $eidikotita_entity->id(), 'eidikotita_entity_revision' => $vid]),
];
}
if ($delete_permission) {
$links['delete'] = [
'title' => $this->t('Delete'),
'url' => Url::fromRoute('eidikotita_entity.revision_delete_confirm', ['eidikotita_entity' => $eidikotita_entity->id(), 'eidikotita_entity_revision' => $vid]),
];
}
$row[] = [
'data' => [
'#type' => 'operations',
'#links' => $links,
],
];
}
$rows[] = $row;
}
}
$build['eidikotita_entity_revisions_table'] = array(
'#theme' => 'table',
'#rows' => $rows,
'#header' => $header,
);
return $build;
}
}
<?php
namespace Drupal\eiek\Controller;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Url;
use Drupal\eiek\Entity\StudentEntityInterface;
/**
* Class StudentEntityController.
*
* Returns responses for Student entity routes.
*
* @package Drupal\eiek\Controller
*/
class StudentEntityController extends ControllerBase implements ContainerInjectionInterface {
/**
* Displays a Student entity revision.
*
* @param int $student_entity_revision
* The Student entity revision ID.
*
* @return array
* An array suitable for drupal_render().
*/
public function revisionShow($student_entity_revision) {
$student_entity = $this->entityManager()->getStorage('student_entity')->loadRevision($student_entity_revision);
$view_builder = $this->entityManager()->getViewBuilder('student_entity');
return $view_builder->view($student_entity);
}
/**
* Page title callback for a Student entity revision.
*
* @param int $student_entity_revision
* The Student entity revision ID.
*
* @return string
* The page title.
*/
public function revisionPageTitle($student_entity_revision) {
$student_entity = $this->entityManager()->getStorage('student_entity')->loadRevision($student_entity_revision);
return $this->t('Revision of %title from %date', array('%title' => $student_entity->label(), '%date' => format_date($student_entity->getRevisionCreationTime())));
}
/**
* Generates an overview table of older revisions of a Student entity .
*
* @param \Drupal\eiek\Entity\StudentEntityInterface $student_entity
* A Student entity object.
*
* @return array
* An array as expected by drupal_render().
*/
public function revisionOverview(StudentEntityInterface $student_entity) {
$account = $this->currentUser();
$langcode = $student_entity->language()->getId();
$langname = $student_entity->language()->getName();
$languages = $student_entity->getTranslationLanguages();
$has_translations = (count($languages) > 1);
$student_entity_storage = $this->entityManager()->getStorage('student_entity');
$build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => $student_entity->label()]) : $this->t('Revisions for %title', ['%title' => $student_entity->label()]);
$header = array($this->t('Revision'), $this->t('Operations'));
$revert_permission = (($account->hasPermission("revert all student entity revisions") || $account->hasPermission('administer student entity entities')));
$delete_permission = (($account->hasPermission("delete all student entity revisions") || $account->hasPermission('administer student entity entities')));
$rows = array();
$vids = $student_entity_storage->revisionIds($student_entity);
$latest_revision = TRUE;
foreach (array_reverse($vids) as $vid) {
/** @var \Drupal\eiek\StudentEntityInterface $revision */
$revision = $student_entity_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->revision_timestamp->value, 'short');
if ($vid != $student_entity->getRevisionId()) {
$link = $this->l($date, new Url('entity.student_entity.revision', ['student_entity' => $student_entity->id(), 'student_entity_revision' => $vid]));
}
else {
$link = $student_entity->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->revision_log_message->value, '#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' => Url::fromRoute('student_entity.revision_revert_confirm', ['student_entity' => $student_entity->id(), 'student_entity_revision' => $vid]),
];
}
if ($delete_permission) {
$links['delete'] = [
'title' => $this->t('Delete'),
'url' => Url::fromRoute('student_entity.revision_delete_confirm', ['student_entity' => $student_entity->id(), 'student_entity_revision' => $vid]),
];
}
$row[] = [
'data' => [
'#type' => 'operations',
'#links' => $links,
],
];
}
$rows[] = $row;
}
}
$build['student_entity_revisions_table'] = array(
'#theme' => 'table',
'#rows' => $rows,
'#header' => $header,
);
return $build;
}
}
......@@ -26,21 +26,6 @@ class EidikotitaEntityHtmlRouteProvider extends AdminHtmlRouteProvider {
$collection->add("entity.{$entity_type_id}.collection", $collection_route);
}
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_type_id}.revision_revert_confirm", $revert_route);
}
if ($delete_route = $this->getRevisionDeleteRoute($entity_type)) {
$collection->add("{$entity_type_id}.revision_delete_confirm", $delete_route);
}
if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
$collection->add("$entity_type_id.settings", $settings_form_route);
......@@ -74,101 +59,7 @@ class EidikotitaEntityHtmlRouteProvider extends AdminHtmlRouteProvider {
}
}
/**
* 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\eiek\Controller\EidikotitaEntityController::revisionOverview',
])
->setRequirement('_permission', 'access eidikotita entity 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\eiek\Controller\EidikotitaEntityController::revisionShow',
'_title_callback' => '\Drupal\eiek\Controller\EidikotitaEntityController::revisionPageTitle',
])
->setRequirement('_permission', 'access eidikotita entity 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\eiek\Form\EidikotitaEntityRevisionRevertForm',
'_title' => 'Revert to earlier revision',
])
->setRequirement('_permission', 'revert all eidikotita entity 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\eiek\Form\EidikotitaEntityRevisionDeleteForm',
'_title' => 'Delete earlier revision',
])
->setRequirement('_permission', 'delete all eidikotita entity revisions')
->setOption('_admin_route', TRUE);
return $route;
}
}
/**
* Gets the settings form route.
......
<?php
namespace Drupal\eiek;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\eiek\Entity\EidikotitaEntityInterface;
/**
* Defines the storage handler class for Eidikotita entity entities.
*
* This extends the base storage class, adding required special handling for
* Eidikotita entity entities.
*
* @ingroup eiek
*/
class EidikotitaEntityStorage extends SqlContentEntityStorage implements EidikotitaEntityStorageInterface {
/**
* {@inheritdoc}
*/
public function revisionIds(EidikotitaEntityInterface $entity) {
return $this->database->query(
'SELECT vid FROM {eidikotita_entity_revision} WHERE id=:id ORDER BY vid',
array(':id' => $entity->id())
)->fetchCol();
}
/**
* {@inheritdoc}
*/
public function userRevisionIds(AccountInterface $account) {
return $this->database->query(
'SELECT vid FROM {eidikotita_entity_field_revision} WHERE uid = :uid ORDER BY vid',
array(':uid' => $account->id())
)->fetchCol();
}
/**
* {@inheritdoc}
*/
public function countDefaultLanguageRevisions(EidikotitaEntityInterface $entity) {
return $this->database->query('SELECT COUNT(*) FROM {eidikotita_entity_field_revision} WHERE id = :id AND default_langcode = 1', array(':id' => $entity->id()))
->fetchField();
}
/**
* {@inheritdoc}
*/
public function clearRevisionsLanguage(LanguageInterface $language) {
return $this->database->update('eidikotita_entity_revision')
->fields(array('langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED))
->condition('langcode', $language->getId())
->execute();
}