Made contact details not revisionable
This commit is contained in:
parent
6d63d5f328
commit
2ae3fcea56
@ -4,13 +4,13 @@
|
||||
* @file
|
||||
* Contains contact_details.page.inc.
|
||||
*
|
||||
* Page callback for Contact Details entities.
|
||||
* Page callback for Contact details entities.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Render\Element;
|
||||
|
||||
/**
|
||||
* Prepares variables for Contact Details templates.
|
||||
* Prepares variables for Contact details templates.
|
||||
*
|
||||
* Default template: contact_details.html.twig.
|
||||
*
|
||||
|
@ -8,7 +8,7 @@ use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
|
||||
/**
|
||||
* Access controller for the Contact Details entity.
|
||||
* Access controller for the Contact details entity.
|
||||
*
|
||||
* @see \Drupal\zencrm_entities\Entity\ContactDetails.
|
||||
*/
|
||||
|
@ -7,7 +7,7 @@ use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Provides routes for Contact Details entities.
|
||||
* Provides routes for Contact details entities.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
@ -22,26 +22,6 @@ class ContactDetailsHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
|
||||
$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);
|
||||
}
|
||||
@ -49,126 +29,6 @@ class ContactDetailsHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
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\zencrm_entities\Controller\ContactDetailsController::revisionOverview',
|
||||
])
|
||||
->setRequirement('_permission', 'access contact details 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\zencrm_entities\Controller\ContactDetailsController::revisionShow',
|
||||
'_title_callback' => '\Drupal\zencrm_entities\Controller\ContactDetailsController::revisionPageTitle',
|
||||
])
|
||||
->setRequirement('_permission', 'access contact details 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\zencrm_entities\Form\ContactDetailsRevisionRevertForm',
|
||||
'_title' => 'Revert to earlier revision',
|
||||
])
|
||||
->setRequirement('_permission', 'revert all contact details 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\zencrm_entities\Form\ContactDetailsRevisionDeleteForm',
|
||||
'_title' => 'Delete earlier revision',
|
||||
])
|
||||
->setRequirement('_permission', 'delete all contact details 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\zencrm_entities\Form\ContactDetailsRevisionRevertTranslationForm',
|
||||
'_title' => 'Revert to earlier revision of a translation',
|
||||
])
|
||||
->setRequirement('_permission', 'revert all contact details revisions')
|
||||
->setOption('_admin_route', TRUE);
|
||||
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the settings form route.
|
||||
*
|
||||
|
@ -7,7 +7,7 @@ use Drupal\Core\Entity\EntityListBuilder;
|
||||
use Drupal\Core\Link;
|
||||
|
||||
/**
|
||||
* Defines a class to build a listing of Contact Details entities.
|
||||
* Defines a class to build a listing of Contact details entities.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
@ -18,7 +18,7 @@ class ContactDetailsListBuilder extends EntityListBuilder {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['id'] = $this->t('Contact Details ID');
|
||||
$header['id'] = $this->t('Contact details ID');
|
||||
$header['name'] = $this->t('Name');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities;
|
||||
|
||||
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\zencrm_entities\Entity\ContactDetailsInterface;
|
||||
|
||||
/**
|
||||
* Defines the storage handler class for Contact Details entities.
|
||||
*
|
||||
* This extends the base storage class, adding required special handling for
|
||||
* Contact Details entities.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class ContactDetailsStorage extends SqlContentEntityStorage implements ContactDetailsStorageInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function revisionIds(ContactDetailsInterface $entity) {
|
||||
return $this->database->query(
|
||||
'SELECT vid FROM {contact_details_revision} WHERE id=:id ORDER BY vid',
|
||||
[':id' => $entity->id()]
|
||||
)->fetchCol();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function userRevisionIds(AccountInterface $account) {
|
||||
return $this->database->query(
|
||||
'SELECT vid FROM {contact_details_field_revision} WHERE uid = :uid ORDER BY vid',
|
||||
[':uid' => $account->id()]
|
||||
)->fetchCol();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function countDefaultLanguageRevisions(ContactDetailsInterface $entity) {
|
||||
return $this->database->query('SELECT COUNT(*) FROM {contact_details_field_revision} WHERE id = :id AND default_langcode = 1', [':id' => $entity->id()])
|
||||
->fetchField();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearRevisionsLanguage(LanguageInterface $language) {
|
||||
return $this->database->update('contact_details_revision')
|
||||
->fields(['langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED])
|
||||
->condition('langcode', $language->getId())
|
||||
->execute();
|
||||
}
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityStorageInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\zencrm_entities\Entity\ContactDetailsInterface;
|
||||
|
||||
/**
|
||||
* Defines the storage handler class for Contact Details entities.
|
||||
*
|
||||
* This extends the base storage class, adding required special handling for
|
||||
* Contact Details entities.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
interface ContactDetailsStorageInterface extends ContentEntityStorageInterface {
|
||||
|
||||
/**
|
||||
* Gets a list of Contact Details revision IDs for a specific Contact Details.
|
||||
*
|
||||
* @param \Drupal\zencrm_entities\Entity\ContactDetailsInterface $entity
|
||||
* The Contact Details entity.
|
||||
*
|
||||
* @return int[]
|
||||
* Contact Details revision IDs (in ascending order).
|
||||
*/
|
||||
public function revisionIds(ContactDetailsInterface $entity);
|
||||
|
||||
/**
|
||||
* Gets a list of revision IDs having a given user as Contact Details author.
|
||||
*
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* The user entity.
|
||||
*
|
||||
* @return int[]
|
||||
* Contact Details revision IDs (in ascending order).
|
||||
*/
|
||||
public function userRevisionIds(AccountInterface $account);
|
||||
|
||||
/**
|
||||
* Counts the number of revisions in the default language.
|
||||
*
|
||||
* @param \Drupal\zencrm_entities\Entity\ContactDetailsInterface $entity
|
||||
* The Contact Details entity.
|
||||
*
|
||||
* @return int
|
||||
* The number of revisions in the default language.
|
||||
*/
|
||||
public function countDefaultLanguageRevisions(ContactDetailsInterface $entity);
|
||||
|
||||
/**
|
||||
* Unsets the language for all Contact Details with the given language.
|
||||
*
|
||||
* @param \Drupal\Core\Language\LanguageInterface $language
|
||||
* The language object.
|
||||
*/
|
||||
public function clearRevisionsLanguage(LanguageInterface $language);
|
||||
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities;
|
||||
|
||||
use Drupal\content_translation\ContentTranslationHandler;
|
||||
|
||||
/**
|
||||
* Defines the translation handler for contact_details.
|
||||
*/
|
||||
class ContactDetailsTranslationHandler extends ContentTranslationHandler {
|
||||
|
||||
// Override here the needed methods from ContentTranslationHandler.
|
||||
|
||||
}
|
@ -1,163 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Controller;
|
||||
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\zencrm_entities\Entity\ContactDetailsInterface;
|
||||
|
||||
/**
|
||||
* Class ContactDetailsController.
|
||||
*
|
||||
* Returns responses for Contact Details routes.
|
||||
*/
|
||||
class ContactDetailsController extends ControllerBase implements ContainerInjectionInterface {
|
||||
|
||||
/**
|
||||
* Displays a Contact Details revision.
|
||||
*
|
||||
* @param int $contact_details_revision
|
||||
* The Contact Details revision ID.
|
||||
*
|
||||
* @return array
|
||||
* An array suitable for drupal_render().
|
||||
*/
|
||||
public function revisionShow($contact_details_revision) {
|
||||
$contact_details = $this->entityManager()->getStorage('contact_details')->loadRevision($contact_details_revision);
|
||||
$view_builder = $this->entityManager()->getViewBuilder('contact_details');
|
||||
|
||||
return $view_builder->view($contact_details);
|
||||
}
|
||||
|
||||
/**
|
||||
* Page title callback for a Contact Details revision.
|
||||
*
|
||||
* @param int $contact_details_revision
|
||||
* The Contact Details revision ID.
|
||||
*
|
||||
* @return string
|
||||
* The page title.
|
||||
*/
|
||||
public function revisionPageTitle($contact_details_revision) {
|
||||
$contact_details = $this->entityManager()->getStorage('contact_details')->loadRevision($contact_details_revision);
|
||||
return $this->t('Revision of %title from %date', ['%title' => $contact_details->label(), '%date' => format_date($contact_details->getRevisionCreationTime())]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an overview table of older revisions of a Contact Details .
|
||||
*
|
||||
* @param \Drupal\zencrm_entities\Entity\ContactDetailsInterface $contact_details
|
||||
* A Contact Details object.
|
||||
*
|
||||
* @return array
|
||||
* An array as expected by drupal_render().
|
||||
*/
|
||||
public function revisionOverview(ContactDetailsInterface $contact_details) {
|
||||
$account = $this->currentUser();
|
||||
$langcode = $contact_details->language()->getId();
|
||||
$langname = $contact_details->language()->getName();
|
||||
$languages = $contact_details->getTranslationLanguages();
|
||||
$has_translations = (count($languages) > 1);
|
||||
$contact_details_storage = $this->entityManager()->getStorage('contact_details');
|
||||
|
||||
$build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => $contact_details->label()]) : $this->t('Revisions for %title', ['%title' => $contact_details->label()]);
|
||||
$header = [$this->t('Revision'), $this->t('Operations')];
|
||||
|
||||
$revert_permission = (($account->hasPermission("revert all contact details revisions") || $account->hasPermission('administer contact details entities')));
|
||||
$delete_permission = (($account->hasPermission("delete all contact details revisions") || $account->hasPermission('administer contact details entities')));
|
||||
|
||||
$rows = [];
|
||||
|
||||
$vids = $contact_details_storage->revisionIds($contact_details);
|
||||
|
||||
$latest_revision = TRUE;
|
||||
|
||||
foreach (array_reverse($vids) as $vid) {
|
||||
/** @var \Drupal\zencrm_entities\ContactDetailsInterface $revision */
|
||||
$revision = $contact_details_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 != $contact_details->getRevisionId()) {
|
||||
$link = $this->l($date, new Url('entity.contact_details.revision', ['contact_details' => $contact_details->id(), 'contact_details_revision' => $vid]));
|
||||
}
|
||||
else {
|
||||
$link = $contact_details->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.contact_details.translation_revert', ['contact_details' => $contact_details->id(), 'contact_details_revision' => $vid, 'langcode' => $langcode]) :
|
||||
Url::fromRoute('entity.contact_details.revision_revert', ['contact_details' => $contact_details->id(), 'contact_details_revision' => $vid]),
|
||||
];
|
||||
}
|
||||
|
||||
if ($delete_permission) {
|
||||
$links['delete'] = [
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => Url::fromRoute('entity.contact_details.revision_delete', ['contact_details' => $contact_details->id(), 'contact_details_revision' => $vid]),
|
||||
];
|
||||
}
|
||||
|
||||
$row[] = [
|
||||
'data' => [
|
||||
'#type' => 'operations',
|
||||
'#links' => $links,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
$build['contact_details_revisions_table'] = [
|
||||
'#theme' => 'table',
|
||||
'#rows' => $rows,
|
||||
'#header' => $header,
|
||||
];
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
}
|
@ -4,26 +4,23 @@ namespace Drupal\zencrm_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\ContentEntityBase;
|
||||
use Drupal\Core\Entity\EntityChangedTrait;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Defines the Contact Details entity.
|
||||
* Defines the Contact details entity.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "contact_details",
|
||||
* label = @Translation("Contact Details"),
|
||||
* label = @Translation("Contact details"),
|
||||
* handlers = {
|
||||
* "storage" = "Drupal\zencrm_entities\ContactDetailsStorage",
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\zencrm_entities\ContactDetailsListBuilder",
|
||||
* "views_data" = "Drupal\zencrm_entities\Entity\ContactDetailsViewsData",
|
||||
* "translation" = "Drupal\zencrm_entities\ContactDetailsTranslationHandler",
|
||||
*
|
||||
* "form" = {
|
||||
* "default" = "Drupal\zencrm_entities\Form\ContactDetailsForm",
|
||||
@ -37,36 +34,26 @@ use Drupal\user\UserInterface;
|
||||
* },
|
||||
* },
|
||||
* base_table = "contact_details",
|
||||
* data_table = "contact_details_field_data",
|
||||
* revision_table = "contact_details_revision",
|
||||
* revision_data_table = "contact_details_field_revision",
|
||||
* translatable = TRUE,
|
||||
* admin_permission = "administer contact details entities",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "revision" = "vid",
|
||||
* "label" = "type",
|
||||
* "label" = "name",
|
||||
* "uuid" = "uuid",
|
||||
* "uid" = "user_id",
|
||||
* "langcode" = "langcode",
|
||||
* "status" = "status",
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/zencrm/contact_details/{contact_details}",
|
||||
* "add-form" = "/zencrm/contact_details/add",
|
||||
* "edit-form" = "/zencrm/contact_details/{contact_details}/edit",
|
||||
* "delete-form" = "/zencrm/contact_details/{contact_details}/delete",
|
||||
* "version-history" = "/zencrm/contact_details/{contact_details}/revisions",
|
||||
* "revision" = "/zencrm/contact_details/{contact_details}/revisions/{contact_details_revision}/view",
|
||||
* "revision_revert" = "/zencrm/contact_details/{contact_details}/revisions/{contact_details_revision}/revert",
|
||||
* "revision_delete" = "/zencrm/contact_details/{contact_details}/revisions/{contact_details_revision}/delete",
|
||||
* "translation_revert" = "/zencrm/contact_details/{contact_details}/revisions/{contact_details_revision}/revert/{langcode}",
|
||||
* "collection" = "/zencrm/contact_details",
|
||||
* "canonical" = "/admin/structure/contact_details/{contact_details}",
|
||||
* "add-form" = "/admin/structure/contact_details/add",
|
||||
* "edit-form" = "/admin/structure/contact_details/{contact_details}/edit",
|
||||
* "delete-form" = "/admin/structure/contact_details/{contact_details}/delete",
|
||||
* "collection" = "/admin/structure/contact_details",
|
||||
* },
|
||||
* field_ui_base_route = "contact_details.settings"
|
||||
* )
|
||||
*/
|
||||
class ContactDetails extends RevisionableContentEntityBase implements ContactDetailsInterface {
|
||||
class ContactDetails extends ContentEntityBase implements ContactDetailsInterface {
|
||||
|
||||
use EntityChangedTrait;
|
||||
|
||||
@ -80,44 +67,6 @@ class ContactDetails extends RevisionableContentEntityBase implements ContactDet
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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 contact_details owner the
|
||||
// revision author.
|
||||
if (!$this->getRevisionUser()) {
|
||||
$this->setRevisionUserId($this->getOwnerId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -201,156 +150,58 @@ class ContactDetails extends RevisionableContentEntityBase implements ContactDet
|
||||
|
||||
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Authored by'))
|
||||
->setDescription(t('The user ID of author of the Contact Details entity.'))
|
||||
->setDescription(t('The user ID of author of the Contact details entity.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setSetting('target_type', 'user')
|
||||
->setSetting('handler', 'default')
|
||||
# ->setDisplayOptions('view', [
|
||||
# 'label' => 'inline',
|
||||
# 'type' => 'author',
|
||||
# 'weight' => 100,
|
||||
# ])
|
||||
# ->setDisplayOptions('form', [
|
||||
# 'type' => 'entity_reference_autocomplete',
|
||||
# 'weight' => 100,
|
||||
# 'settings' => [
|
||||
# 'match_operator' => 'CONTAINS',
|
||||
# 'size' => '60',
|
||||
# 'autocomplete_type' => 'tags',
|
||||
# 'placeholder' => '',
|
||||
# ],
|
||||
# ])
|
||||
->setTranslatable(TRUE);
|
||||
|
||||
|
||||
// Type field is used in entity reference fields etc
|
||||
// so it is not exposed to user configuration.
|
||||
$fields['type'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Type'))
|
||||
->setDescription(t('E.g. Home, Business, Temporary'))
|
||||
->setDisplayOptions('form', [
|
||||
->setTranslatable(TRUE)
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'text',
|
||||
'type' => 'author',
|
||||
'weight' => 0,
|
||||
])
|
||||
->setDisplayOptions('view', array(
|
||||
'label' => 'hidden',
|
||||
'type' => 'string',
|
||||
'weight' => 0,
|
||||
))
|
||||
->setRequired(TRUE);
|
||||
|
||||
|
||||
// Person field is always set from the context so no form or display required.
|
||||
$fields['person'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Person'))
|
||||
->setDescription(t('The person this profile is of.'))
|
||||
->setSetting('target_type', 'person')
|
||||
->setRequired(TRUE);
|
||||
|
||||
// Type field is used for mailings,
|
||||
// so it is not exposed to user configuration.
|
||||
$fields['email'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Email Address'))
|
||||
->setSettings(array(
|
||||
'default_value' => '',
|
||||
'max_length' => 30,
|
||||
'text_processing' => 0,
|
||||
))
|
||||
->setDisplayOptions('view', array(
|
||||
'label' => 'hidden',
|
||||
'type' => 'string',
|
||||
'weight' => 0,
|
||||
))
|
||||
->setDisplayOptions('form', array(
|
||||
'type' => 'string_textfield',
|
||||
'weight' => 0,
|
||||
));
|
||||
|
||||
$fields['phone'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Main Phone Number'))
|
||||
->setDisplayConfigurable('view', TRUE)
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->setSettings(array(
|
||||
'default_value' => '',
|
||||
'max_length' => 20,
|
||||
'text_processing' => 0,
|
||||
))
|
||||
->setDisplayOptions('view', array(
|
||||
'label' => 'above',
|
||||
'type' => 'string',
|
||||
'weight' => 2,
|
||||
))
|
||||
->setDisplayOptions('form', array(
|
||||
'type' => 'string_textfield',
|
||||
'weight' => 2,
|
||||
));
|
||||
|
||||
$fields['phone2'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Alternative Phone Number'))
|
||||
->setSettings(array(
|
||||
'default_value' => '',
|
||||
'max_length' => 20,
|
||||
'text_processing' => 0,
|
||||
))
|
||||
->setDisplayConfigurable('view', TRUE)
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->setDisplayOptions('view', array(
|
||||
'label' => 'above',
|
||||
'type' => 'string',
|
||||
'weight' => 3,
|
||||
))
|
||||
->setDisplayOptions('form', array(
|
||||
'type' => 'string_textfield',
|
||||
'weight' => 3,
|
||||
));
|
||||
|
||||
$fields['postal_address'] = BaseFieldDefinition::create('string_long')
|
||||
->setLabel(t('Postal Address'))
|
||||
->setDescription(t('Full address, apart from post code.'))
|
||||
->setDisplayConfigurable('view', TRUE)
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->setSettings(array(
|
||||
'default_value' => '',
|
||||
'max_length' => 255,
|
||||
'text_processing' => 0,
|
||||
))
|
||||
->setDisplayOptions('view', array(
|
||||
'label' => 'above',
|
||||
'type' => 'text',
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'entity_reference_autocomplete',
|
||||
'weight' => 5,
|
||||
))
|
||||
->setDisplayOptions('form', array(
|
||||
'type' => 'string_textarea',
|
||||
'weight' => 5,
|
||||
));
|
||||
'settings' => [
|
||||
'match_operator' => 'CONTAINS',
|
||||
'size' => '60',
|
||||
'autocomplete_type' => 'tags',
|
||||
'placeholder' => '',
|
||||
],
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->setDisplayConfigurable('view', TRUE);
|
||||
|
||||
$fields['post_code'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Post Code'))
|
||||
->setSettings(array(
|
||||
'default_value' => '',
|
||||
'max_length' => 10,
|
||||
$fields['name'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Name'))
|
||||
->setDescription(t('The name of the Contact details entity.'))
|
||||
->setSettings([
|
||||
'max_length' => 50,
|
||||
'text_processing' => 0,
|
||||
))
|
||||
->setDisplayOptions('view', array(
|
||||
])
|
||||
->setDefaultValue('')
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'above',
|
||||
'type' => 'string',
|
||||
'weight' => 6,
|
||||
))
|
||||
->setDisplayOptions('form', array(
|
||||
'weight' => -4,
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'string_textfield',
|
||||
'weight' => 6,
|
||||
));
|
||||
'weight' => -4,
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->setDisplayConfigurable('view', TRUE)
|
||||
->setRequired(TRUE);
|
||||
|
||||
$fields['status'] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Enabled'))
|
||||
->setDescription(t('If this is ticked then this set of contact details is active.'))
|
||||
->setRevisionable(TRUE)
|
||||
# ->setDisplayOptions('form', [
|
||||
# 'type' => 'boolean_checkbox',
|
||||
# 'weight' => -3,
|
||||
# ])
|
||||
->setDefaultValue(TRUE);
|
||||
->setLabel(t('Publishing status'))
|
||||
->setDescription(t('A boolean indicating whether the Contact details is published.'))
|
||||
->setDefaultValue(TRUE)
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'boolean_checkbox',
|
||||
'weight' => -3,
|
||||
]);
|
||||
|
||||
$fields['created'] = BaseFieldDefinition::create('created')
|
||||
->setLabel(t('Created'))
|
||||
@ -360,13 +211,6 @@ class ContactDetails extends RevisionableContentEntityBase implements ContactDet
|
||||
->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;
|
||||
}
|
||||
|
||||
|
@ -3,114 +3,75 @@
|
||||
namespace Drupal\zencrm_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 Contact Details entities.
|
||||
* Provides an interface for defining Contact details entities.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
interface ContactDetailsInterface extends ContentEntityInterface, RevisionLogInterface, EntityChangedInterface, EntityOwnerInterface {
|
||||
interface ContactDetailsInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
|
||||
/**
|
||||
* Gets the Contact Details name.
|
||||
* Gets the Contact details name.
|
||||
*
|
||||
* @return string
|
||||
* Name of the Contact Details.
|
||||
* Name of the Contact details.
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Sets the Contact Details name.
|
||||
* Sets the Contact details name.
|
||||
*
|
||||
* @param string $name
|
||||
* The Contact Details name.
|
||||
* The Contact details name.
|
||||
*
|
||||
* @return \Drupal\zencrm_entities\Entity\ContactDetailsInterface
|
||||
* The called Contact Details entity.
|
||||
* The called Contact details entity.
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* Gets the Contact Details creation timestamp.
|
||||
* Gets the Contact details creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* Creation timestamp of the Contact Details.
|
||||
* Creation timestamp of the Contact details.
|
||||
*/
|
||||
public function getCreatedTime();
|
||||
|
||||
/**
|
||||
* Sets the Contact Details creation timestamp.
|
||||
* Sets the Contact details creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The Contact Details creation timestamp.
|
||||
* The Contact details creation timestamp.
|
||||
*
|
||||
* @return \Drupal\zencrm_entities\Entity\ContactDetailsInterface
|
||||
* The called Contact Details entity.
|
||||
* The called Contact details entity.
|
||||
*/
|
||||
public function setCreatedTime($timestamp);
|
||||
|
||||
/**
|
||||
* Returns the Contact Details published status indicator.
|
||||
* Returns the Contact details published status indicator.
|
||||
*
|
||||
* Unpublished Contact Details are only visible to restricted users.
|
||||
* Unpublished Contact details are only visible to restricted users.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the Contact Details is published.
|
||||
* TRUE if the Contact details is published.
|
||||
*/
|
||||
public function isPublished();
|
||||
|
||||
/**
|
||||
* Sets the published status of a Contact Details.
|
||||
* Sets the published status of a Contact details.
|
||||
*
|
||||
* @param bool $published
|
||||
* TRUE to set this Contact Details to published, FALSE to set it to unpublished.
|
||||
* TRUE to set this Contact details to published, FALSE to set it to unpublished.
|
||||
*
|
||||
* @return \Drupal\zencrm_entities\Entity\ContactDetailsInterface
|
||||
* The called Contact Details entity.
|
||||
* The called Contact details entity.
|
||||
*/
|
||||
public function setPublished($published);
|
||||
|
||||
/**
|
||||
* Gets the Contact Details revision creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* The UNIX timestamp of when this revision was created.
|
||||
*/
|
||||
public function getRevisionCreationTime();
|
||||
|
||||
/**
|
||||
* Sets the Contact Details revision creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The UNIX timestamp of when this revision was created.
|
||||
*
|
||||
* @return \Drupal\zencrm_entities\Entity\ContactDetailsInterface
|
||||
* The called Contact Details entity.
|
||||
*/
|
||||
public function setRevisionCreationTime($timestamp);
|
||||
|
||||
/**
|
||||
* Gets the Contact Details revision author.
|
||||
*
|
||||
* @return \Drupal\user\UserInterface
|
||||
* The user entity for the revision author.
|
||||
*/
|
||||
public function getRevisionUser();
|
||||
|
||||
/**
|
||||
* Sets the Contact Details revision author.
|
||||
*
|
||||
* @param int $uid
|
||||
* The user ID of the revision author.
|
||||
*
|
||||
* @return \Drupal\zencrm_entities\Entity\ContactDetailsInterface
|
||||
* The called Contact Details entity.
|
||||
*/
|
||||
public function setRevisionUserId($uid);
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ namespace Drupal\zencrm_entities\Entity;
|
||||
use Drupal\views\EntityViewsData;
|
||||
|
||||
/**
|
||||
* Provides Views data for Contact Details entities.
|
||||
* Provides Views data for Contact details entities.
|
||||
*/
|
||||
class ContactDetailsViewsData extends EntityViewsData {
|
||||
|
||||
|
@ -5,7 +5,7 @@ namespace Drupal\zencrm_entities\Form;
|
||||
use Drupal\Core\Entity\ContentEntityDeleteForm;
|
||||
|
||||
/**
|
||||
* Provides a form for deleting Contact Details entities.
|
||||
* Provides a form for deleting Contact details entities.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
|
@ -6,7 +6,7 @@ use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Form controller for Contact Details edit forms.
|
||||
* Form controller for Contact details edit forms.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
@ -19,15 +19,6 @@ class ContactDetailsForm extends ContentEntityForm {
|
||||
/* @var $entity \Drupal\zencrm_entities\Entity\ContactDetails */
|
||||
$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;
|
||||
@ -39,29 +30,17 @@ class ContactDetailsForm extends ContentEntityForm {
|
||||
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 Contact Details.', [
|
||||
drupal_set_message($this->t('Created the %label Contact details.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Contact Details.', [
|
||||
drupal_set_message($this->t('Saved the %label Contact details.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
}
|
||||
|
@ -1,123 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_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 Contact Details revision.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class ContactDetailsRevisionDeleteForm extends ConfirmFormBase {
|
||||
|
||||
|
||||
/**
|
||||
* The Contact Details revision.
|
||||
*
|
||||
* @var \Drupal\zencrm_entities\Entity\ContactDetailsInterface
|
||||
*/
|
||||
protected $revision;
|
||||
|
||||
/**
|
||||
* The Contact Details storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $ContactDetailsStorage;
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
* @var \Drupal\Core\Database\Connection
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* Constructs a new ContactDetailsRevisionDeleteForm.
|
||||
*
|
||||
* @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->ContactDetailsStorage = $entity_storage;
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
$entity_manager = $container->get('entity.manager');
|
||||
return new static(
|
||||
$entity_manager->getStorage('contact_details'),
|
||||
$container->get('database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'contact_details_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.contact_details.version_history', ['contact_details' => $this->revision->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return t('Delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $contact_details_revision = NULL) {
|
||||
$this->revision = $this->ContactDetailsStorage->loadRevision($contact_details_revision);
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->ContactDetailsStorage->deleteRevision($this->revision->getRevisionId());
|
||||
|
||||
$this->logger('content')->notice('Contact Details: deleted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
|
||||
drupal_set_message(t('Revision from %revision-date of Contact Details %title has been deleted.', ['%revision-date' => format_date($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()]));
|
||||
$form_state->setRedirect(
|
||||
'entity.contact_details.canonical',
|
||||
['contact_details' => $this->revision->id()]
|
||||
);
|
||||
if ($this->connection->query('SELECT COUNT(DISTINCT vid) FROM {contact_details_field_revision} WHERE id = :id', [':id' => $this->revision->id()])->fetchField() > 1) {
|
||||
$form_state->setRedirect(
|
||||
'entity.contact_details.version_history',
|
||||
['contact_details' => $this->revision->id()]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,149 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_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\zencrm_entities\Entity\ContactDetailsInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for reverting a Contact Details revision.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class ContactDetailsRevisionRevertForm extends ConfirmFormBase {
|
||||
|
||||
|
||||
/**
|
||||
* The Contact Details revision.
|
||||
*
|
||||
* @var \Drupal\zencrm_entities\Entity\ContactDetailsInterface
|
||||
*/
|
||||
protected $revision;
|
||||
|
||||
/**
|
||||
* The Contact Details storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $ContactDetailsStorage;
|
||||
|
||||
/**
|
||||
* The date formatter service.
|
||||
*
|
||||
* @var \Drupal\Core\Datetime\DateFormatterInterface
|
||||
*/
|
||||
protected $dateFormatter;
|
||||
|
||||
/**
|
||||
* Constructs a new ContactDetailsRevisionRevertForm.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
|
||||
* The Contact Details storage.
|
||||
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
|
||||
* The date formatter service.
|
||||
*/
|
||||
public function __construct(EntityStorageInterface $entity_storage, DateFormatterInterface $date_formatter) {
|
||||
$this->ContactDetailsStorage = $entity_storage;
|
||||
$this->dateFormatter = $date_formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager')->getStorage('contact_details'),
|
||||
$container->get('date.formatter')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'contact_details_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.contact_details.version_history', ['contact_details' => $this->revision->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return t('Revert');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $contact_details_revision = NULL) {
|
||||
$this->revision = $this->ContactDetailsStorage->loadRevision($contact_details_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('Contact Details: reverted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
|
||||
drupal_set_message(t('Contact Details %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.contact_details.version_history',
|
||||
['contact_details' => $this->revision->id()]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a revision to be reverted.
|
||||
*
|
||||
* @param \Drupal\zencrm_entities\Entity\ContactDetailsInterface $revision
|
||||
* The revision to be reverted.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*
|
||||
* @return \Drupal\zencrm_entities\Entity\ContactDetailsInterface
|
||||
* The prepared revision ready to be stored.
|
||||
*/
|
||||
protected function prepareRevertedRevision(ContactDetailsInterface $revision, FormStateInterface $form_state) {
|
||||
$revision->setNewRevision();
|
||||
$revision->isDefaultRevision(TRUE);
|
||||
$revision->setRevisionCreationTime(REQUEST_TIME);
|
||||
|
||||
return $revision;
|
||||
}
|
||||
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Form;
|
||||
|
||||
use Drupal\Core\Datetime\DateFormatterInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\zencrm_entities\Entity\ContactDetailsInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for reverting a Contact Details revision for a single translation.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class ContactDetailsRevisionRevertTranslationForm extends ContactDetailsRevisionRevertForm {
|
||||
|
||||
|
||||
/**
|
||||
* The language to be reverted.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $langcode;
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* Constructs a new ContactDetailsRevisionRevertTranslationForm.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
|
||||
* The Contact Details 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('contact_details'),
|
||||
$container->get('date.formatter'),
|
||||
$container->get('language_manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'contact_details_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, $contact_details_revision = NULL, $langcode = NULL) {
|
||||
$this->langcode = $langcode;
|
||||
$form = parent::buildForm($form, $form_state, $contact_details_revision);
|
||||
|
||||
$form['revert_untranslated_fields'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Revert content shared among translations'),
|
||||
'#default_value' => FALSE,
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function prepareRevertedRevision(ContactDetailsInterface $revision, FormStateInterface $form_state) {
|
||||
$revert_untranslated_fields = $form_state->getValue('revert_untranslated_fields');
|
||||
|
||||
/** @var \Drupal\zencrm_entities\Entity\ContactDetailsInterface $default_revision */
|
||||
$latest_revision = $this->ContactDetailsStorage->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;
|
||||
}
|
||||
|
||||
}
|
@ -35,7 +35,7 @@ class ContactDetailsSettingsForm extends FormBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the settings form for Contact Details entities.
|
||||
* Defines the settings form for Contact details entities.
|
||||
*
|
||||
* @param array $form
|
||||
* An associative array containing the structure of the form.
|
||||
@ -46,7 +46,7 @@ class ContactDetailsSettingsForm extends FormBase {
|
||||
* Form definition array.
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['contactdetails_settings']['#markup'] = 'Settings form for Contact Details entities. Manage field settings here.';
|
||||
$form['contactdetails_settings']['#markup'] = 'Settings form for Contact details entities. Manage field settings here.';
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
{#
|
||||
/**
|
||||
* @file contact_details.html.twig
|
||||
* Default theme implementation to present Contact Details data.
|
||||
* Default theme implementation to present Contact details data.
|
||||
*
|
||||
* This template is used when viewing Contact Details pages.
|
||||
* This template is used when viewing Contact details pages.
|
||||
*
|
||||
*
|
||||
* Available variables:
|
||||
|
@ -24,3 +24,8 @@ entity.person.add_form:
|
||||
title: 'Add Person'
|
||||
appears_on:
|
||||
- entity.person.collection
|
||||
entity.contact_details.add_form:
|
||||
route_name: entity.contact_details.add_form
|
||||
title: 'Add Contact details'
|
||||
appears_on:
|
||||
- entity.contact_details.collection
|
||||
|
@ -58,3 +58,17 @@ person.admin.structure.settings:
|
||||
description: 'Configure Person entities'
|
||||
route_name: person.settings
|
||||
parent: system.admin_structure
|
||||
|
||||
# Contact details menu items definition
|
||||
entity.contact_details.collection:
|
||||
title: 'Contact details list'
|
||||
route_name: entity.contact_details.collection
|
||||
description: 'List Contact details entities'
|
||||
parent: system.admin_structure
|
||||
weight: 100
|
||||
|
||||
contact_details.admin.structure.settings:
|
||||
title: 'Contact details settings'
|
||||
description: 'Configure Contact details entities'
|
||||
route_name: contact_details.settings
|
||||
parent: system.admin_structure
|
||||
|
@ -97,3 +97,25 @@ entity.person.delete_form:
|
||||
title: Delete
|
||||
weight: 10
|
||||
|
||||
# Contact details routing definition
|
||||
contact_details.settings_tab:
|
||||
route_name: contact_details.settings
|
||||
title: 'Settings'
|
||||
base_route: contact_details.settings
|
||||
|
||||
entity.contact_details.canonical:
|
||||
route_name: entity.contact_details.canonical
|
||||
base_route: entity.contact_details.canonical
|
||||
title: 'View'
|
||||
|
||||
entity.contact_details.edit_form:
|
||||
route_name: entity.contact_details.edit_form
|
||||
base_route: entity.contact_details.canonical
|
||||
title: 'Edit'
|
||||
|
||||
entity.contact_details.delete_form:
|
||||
route_name: entity.contact_details.delete_form
|
||||
base_route: entity.contact_details.canonical
|
||||
title: Delete
|
||||
weight: 10
|
||||
|
||||
|
@ -107,3 +107,22 @@ view published person entities:
|
||||
|
||||
view unpublished person entities:
|
||||
title: 'View unpublished Person entities'
|
||||
add contact details entities:
|
||||
title: 'Create new Contact details entities'
|
||||
|
||||
administer contact details entities:
|
||||
title: 'Administer Contact details entities'
|
||||
description: 'Allow to access the administration form to configure Contact details entities.'
|
||||
restrict access: true
|
||||
|
||||
delete contact details entities:
|
||||
title: 'Delete Contact details entities'
|
||||
|
||||
edit contact details entities:
|
||||
title: 'Edit Contact details entities'
|
||||
|
||||
view published contact details entities:
|
||||
title: 'View published Contact details entities'
|
||||
|
||||
view unpublished contact details entities:
|
||||
title: 'View unpublished Contact details entities'
|
||||
|
Reference in New Issue
Block a user