removed profile files ready for regenerating as unrevisionable
This commit is contained in:
parent
10b84fb208
commit
1e1bfe0ca9
@ -1,12 +0,0 @@
|
||||
zencrm_entities.profile_type.*:
|
||||
type: config_entity
|
||||
label: 'Profile type config'
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'ID'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
uuid:
|
||||
type: string
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains profile.page.inc.
|
||||
*
|
||||
* Page callback for Profile entities.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Render\Element;
|
||||
|
||||
/**
|
||||
* Prepares variables for Profile templates.
|
||||
*
|
||||
* Default template: profile.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_profile(array &$variables) {
|
||||
// Fetch Profile Entity Object.
|
||||
$profile = $variables['elements']['#profile'];
|
||||
|
||||
// Helpful $content variable for templates.
|
||||
foreach (Element::children($variables['elements']) as $key) {
|
||||
$variables['content'][$key] = $variables['elements'][$key];
|
||||
}
|
||||
}
|
@ -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\ProfileInterface;
|
||||
|
||||
/**
|
||||
* Class ProfileController.
|
||||
*
|
||||
* Returns responses for Profile routes.
|
||||
*/
|
||||
class ProfileController extends ControllerBase implements ContainerInjectionInterface {
|
||||
|
||||
/**
|
||||
* Displays a Profile revision.
|
||||
*
|
||||
* @param int $profile_revision
|
||||
* The Profile revision ID.
|
||||
*
|
||||
* @return array
|
||||
* An array suitable for drupal_render().
|
||||
*/
|
||||
public function revisionShow($profile_revision) {
|
||||
$profile = $this->entityManager()->getStorage('profile')->loadRevision($profile_revision);
|
||||
$view_builder = $this->entityManager()->getViewBuilder('profile');
|
||||
|
||||
return $view_builder->view($profile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Page title callback for a Profile revision.
|
||||
*
|
||||
* @param int $profile_revision
|
||||
* The Profile revision ID.
|
||||
*
|
||||
* @return string
|
||||
* The page title.
|
||||
*/
|
||||
public function revisionPageTitle($profile_revision) {
|
||||
$profile = $this->entityManager()->getStorage('profile')->loadRevision($profile_revision);
|
||||
return $this->t('Revision of %title from %date', ['%title' => $profile->label(), '%date' => format_date($profile->getRevisionCreationTime())]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an overview table of older revisions of a Profile .
|
||||
*
|
||||
* @param \Drupal\zencrm_entities\Entity\ProfileInterface $profile
|
||||
* A Profile object.
|
||||
*
|
||||
* @return array
|
||||
* An array as expected by drupal_render().
|
||||
*/
|
||||
public function revisionOverview(ProfileInterface $profile) {
|
||||
$account = $this->currentUser();
|
||||
$langcode = $profile->language()->getId();
|
||||
$langname = $profile->language()->getName();
|
||||
$languages = $profile->getTranslationLanguages();
|
||||
$has_translations = (count($languages) > 1);
|
||||
$profile_storage = $this->entityManager()->getStorage('profile');
|
||||
|
||||
$build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => $profile->label()]) : $this->t('Revisions for %title', ['%title' => $profile->label()]);
|
||||
$header = [$this->t('Revision'), $this->t('Operations')];
|
||||
|
||||
$revert_permission = (($account->hasPermission("revert all profile revisions") || $account->hasPermission('administer profile entities')));
|
||||
$delete_permission = (($account->hasPermission("delete all profile revisions") || $account->hasPermission('administer profile entities')));
|
||||
|
||||
$rows = [];
|
||||
|
||||
$vids = $profile_storage->revisionIds($profile);
|
||||
|
||||
$latest_revision = TRUE;
|
||||
|
||||
foreach (array_reverse($vids) as $vid) {
|
||||
/** @var \Drupal\zencrm_entities\ProfileInterface $revision */
|
||||
$revision = $profile_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 != $profile->getRevisionId()) {
|
||||
$link = $this->l($date, new Url('entity.profile.revision', ['profile' => $profile->id(), 'profile_revision' => $vid]));
|
||||
}
|
||||
else {
|
||||
$link = $profile->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.profile.translation_revert', ['profile' => $profile->id(), 'profile_revision' => $vid, 'langcode' => $langcode]) :
|
||||
Url::fromRoute('entity.profile.revision_revert', ['profile' => $profile->id(), 'profile_revision' => $vid]),
|
||||
];
|
||||
}
|
||||
|
||||
if ($delete_permission) {
|
||||
$links['delete'] = [
|
||||
'title' => $this->t('Delete'),
|
||||
'url' => Url::fromRoute('entity.profile.revision_delete', ['profile' => $profile->id(), 'profile_revision' => $vid]),
|
||||
];
|
||||
}
|
||||
|
||||
$row[] = [
|
||||
'data' => [
|
||||
'#type' => 'operations',
|
||||
'#links' => $links,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
$build['profile_revisions_table'] = [
|
||||
'#theme' => 'table',
|
||||
'#rows' => $rows,
|
||||
'#header' => $header,
|
||||
];
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
}
|
@ -1,263 +0,0 @@
|
||||
<?php
|
||||
|
||||
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\EntityChangedTrait;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Defines the Profile entity.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "profile",
|
||||
* label = @Translation("Profile"),
|
||||
* bundle_label = @Translation("Profile type"),
|
||||
* handlers = {
|
||||
* "storage" = "Drupal\zencrm_entities\ProfileStorage",
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\zencrm_entities\ProfileListBuilder",
|
||||
* "views_data" = "Drupal\zencrm_entities\Entity\ProfileViewsData",
|
||||
* "translation" = "Drupal\zencrm_entities\ProfileTranslationHandler",
|
||||
*
|
||||
* "form" = {
|
||||
* "default" = "Drupal\zencrm_entities\Form\ProfileForm",
|
||||
* "add" = "Drupal\zencrm_entities\Form\ProfileForm",
|
||||
* "edit" = "Drupal\zencrm_entities\Form\ProfileForm",
|
||||
* "delete" = "Drupal\zencrm_entities\Form\ProfileDeleteForm",
|
||||
* },
|
||||
* "access" = "Drupal\zencrm_entities\ProfileAccessControlHandler",
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\zencrm_entities\ProfileHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* base_table = "profile",
|
||||
* data_table = "profile_field_data",
|
||||
* revision_table = "profile_revision",
|
||||
* revision_data_table = "profile_field_revision",
|
||||
* translatable = TRUE,
|
||||
* admin_permission = "administer profile entities",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "revision" = "vid",
|
||||
* "bundle" = "type",
|
||||
* "label" = "name",
|
||||
* "uuid" = "uuid",
|
||||
* "uid" = "user_id",
|
||||
* "langcode" = "langcode",
|
||||
* "status" = "status",
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/zencrm/profile/{profile}",
|
||||
* "add-page" = "/zencrm/profile/add",
|
||||
* "add-form" = "/zencrm/profile/add/{profile_type}",
|
||||
* "edit-form" = "/zencrm/profile/{profile}/edit",
|
||||
* "delete-form" = "/zencrm/profile/{profile}/delete",
|
||||
* "version-history" = "/zencrm/profile/{profile}/revisions",
|
||||
* "revision" = "/zencrm/profile/{profile}/revisions/{profile_revision}/view",
|
||||
* "revision_revert" = "/zencrm/profile/{profile}/revisions/{profile_revision}/revert",
|
||||
* "revision_delete" = "/zencrm/profile/{profile}/revisions/{profile_revision}/delete",
|
||||
* "translation_revert" = "/zencrm/profile/{profile}/revisions/{profile_revision}/revert/{langcode}",
|
||||
* "collection" = "/zencrm/profile",
|
||||
* },
|
||||
* bundle_entity_type = "profile_type",
|
||||
* field_ui_base_route = "entity.profile_type.edit_form"
|
||||
* )
|
||||
*/
|
||||
class Profile extends RevisionableContentEntityBase implements ProfileInterface {
|
||||
|
||||
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 profile 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 Profile entity.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setSetting('target_type', 'user')
|
||||
->setSetting('handler', 'default')
|
||||
->setTranslatable(TRUE);
|
||||
# ->setDisplayOptions('form', [
|
||||
# 'type' => 'entity_reference_autocomplete',
|
||||
# 'weight' => 5,
|
||||
# 'settings' => [
|
||||
# 'match_operator' => 'CONTAINS',
|
||||
# 'size' => '60',
|
||||
# 'autocomplete_type' => 'tags',
|
||||
# 'placeholder' => '',
|
||||
# ],
|
||||
# ]);
|
||||
|
||||
$fields['person'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Person'))
|
||||
->setDescription(t('The person this profile is of.'))
|
||||
->setSetting('target_type', 'person');
|
||||
|
||||
// This field is computed in a presave hook.
|
||||
$fields['name'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Name'))
|
||||
->setDescription(t('The name of this profile instance.'))
|
||||
->setRevisionable(TRUE);
|
||||
|
||||
$fields['status'] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Publishing status'))
|
||||
->setDescription(t('A boolean indicating whether the Profile is published.'))
|
||||
->setRevisionable(TRUE)
|
||||
# ->setDisplayOptions('form', [
|
||||
# 'type' => 'boolean_checkbox',
|
||||
# 'weight' => -3,
|
||||
# ])
|
||||
->setDefaultValue(TRUE);
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
<?php
|
||||
|
||||
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 Profile entities.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
interface ProfileInterface extends ContentEntityInterface, RevisionLogInterface, EntityChangedInterface, EntityOwnerInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
|
||||
/**
|
||||
* Gets the Profile name.
|
||||
*
|
||||
* @return string
|
||||
* Name of the Profile.
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Sets the Profile name.
|
||||
*
|
||||
* @param string $name
|
||||
* The Profile name.
|
||||
*
|
||||
* @return \Drupal\zencrm_entities\Entity\ProfileInterface
|
||||
* The called Profile entity.
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* Gets the Profile creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* Creation timestamp of the Profile.
|
||||
*/
|
||||
public function getCreatedTime();
|
||||
|
||||
/**
|
||||
* Sets the Profile creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The Profile creation timestamp.
|
||||
*
|
||||
* @return \Drupal\zencrm_entities\Entity\ProfileInterface
|
||||
* The called Profile entity.
|
||||
*/
|
||||
public function setCreatedTime($timestamp);
|
||||
|
||||
/**
|
||||
* Returns the Profile published status indicator.
|
||||
*
|
||||
* Unpublished Profile are only visible to restricted users.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the Profile is published.
|
||||
*/
|
||||
public function isPublished();
|
||||
|
||||
/**
|
||||
* Sets the published status of a Profile.
|
||||
*
|
||||
* @param bool $published
|
||||
* TRUE to set this Profile to published, FALSE to set it to unpublished.
|
||||
*
|
||||
* @return \Drupal\zencrm_entities\Entity\ProfileInterface
|
||||
* The called Profile entity.
|
||||
*/
|
||||
public function setPublished($published);
|
||||
|
||||
/**
|
||||
* Gets the Profile revision creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* The UNIX timestamp of when this revision was created.
|
||||
*/
|
||||
public function getRevisionCreationTime();
|
||||
|
||||
/**
|
||||
* Sets the Profile revision creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The UNIX timestamp of when this revision was created.
|
||||
*
|
||||
* @return \Drupal\zencrm_entities\Entity\ProfileInterface
|
||||
* The called Profile entity.
|
||||
*/
|
||||
public function setRevisionCreationTime($timestamp);
|
||||
|
||||
/**
|
||||
* Gets the Profile revision author.
|
||||
*
|
||||
* @return \Drupal\user\UserInterface
|
||||
* The user entity for the revision author.
|
||||
*/
|
||||
public function getRevisionUser();
|
||||
|
||||
/**
|
||||
* Sets the Profile revision author.
|
||||
*
|
||||
* @param int $uid
|
||||
* The user ID of the revision author.
|
||||
*
|
||||
* @return \Drupal\zencrm_entities\Entity\ProfileInterface
|
||||
* The called Profile entity.
|
||||
*/
|
||||
public function setRevisionUserId($uid);
|
||||
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
||||
|
||||
/**
|
||||
* Defines the Profile type entity.
|
||||
*
|
||||
* @ConfigEntityType(
|
||||
* id = "profile_type",
|
||||
* label = @Translation("Profile type"),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\zencrm_entities\ProfileTypeListBuilder",
|
||||
* "form" = {
|
||||
* "add" = "Drupal\zencrm_entities\Form\ProfileTypeForm",
|
||||
* "edit" = "Drupal\zencrm_entities\Form\ProfileTypeForm",
|
||||
* "delete" = "Drupal\zencrm_entities\Form\ProfileTypeDeleteForm"
|
||||
* },
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\zencrm_entities\ProfileTypeHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* config_prefix = "profile_type",
|
||||
* admin_permission = "administer site configuration",
|
||||
* bundle_of = "profile",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label",
|
||||
* "uuid" = "uuid"
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/admin/zencrm/profile_type/{profile_type}",
|
||||
* "add-form" = "/admin/zencrm/profile_type/add",
|
||||
* "edit-form" = "/admin/zencrm/profile_type/{profile_type}/edit",
|
||||
* "delete-form" = "/admin/zencrm/profile_type/{profile_type}/delete",
|
||||
* "collection" = "/admin/zencrm/profile_type"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class ProfileType extends ConfigEntityBundleBase implements ProfileTypeInterface {
|
||||
|
||||
/**
|
||||
* The Profile type ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* The Profile type label.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining Profile type entities.
|
||||
*/
|
||||
interface ProfileTypeInterface extends ConfigEntityInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Entity;
|
||||
|
||||
use Drupal\views\EntityViewsData;
|
||||
|
||||
/**
|
||||
* Provides Views data for Profile entities.
|
||||
*/
|
||||
class ProfileViewsData extends EntityViewsData {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getViewsData() {
|
||||
$data = parent::getViewsData();
|
||||
|
||||
// Additional information for Views integration, such as table joins, can be
|
||||
// put here.
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityDeleteForm;
|
||||
|
||||
/**
|
||||
* Provides a form for deleting Profile entities.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class ProfileDeleteForm extends ContentEntityDeleteForm {
|
||||
|
||||
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Form controller for Profile edit forms.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class ProfileForm extends ContentEntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
/* @var $entity \Drupal\zencrm_entities\Entity\Profile */
|
||||
$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 Profile.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Profile.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirect('entity.profile.canonical', ['profile' => $entity->id()]);
|
||||
}
|
||||
|
||||
}
|
@ -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 Profile revision.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class ProfileRevisionDeleteForm extends ConfirmFormBase {
|
||||
|
||||
|
||||
/**
|
||||
* The Profile revision.
|
||||
*
|
||||
* @var \Drupal\zencrm_entities\Entity\ProfileInterface
|
||||
*/
|
||||
protected $revision;
|
||||
|
||||
/**
|
||||
* The Profile storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $ProfileStorage;
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
* @var \Drupal\Core\Database\Connection
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* Constructs a new ProfileRevisionDeleteForm.
|
||||
*
|
||||
* @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->ProfileStorage = $entity_storage;
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
$entity_manager = $container->get('entity.manager');
|
||||
return new static(
|
||||
$entity_manager->getStorage('profile'),
|
||||
$container->get('database')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'profile_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.profile.version_history', ['profile' => $this->revision->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return t('Delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $profile_revision = NULL) {
|
||||
$this->revision = $this->ProfileStorage->loadRevision($profile_revision);
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->ProfileStorage->deleteRevision($this->revision->getRevisionId());
|
||||
|
||||
$this->logger('content')->notice('Profile: deleted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
|
||||
drupal_set_message(t('Revision from %revision-date of Profile %title has been deleted.', ['%revision-date' => format_date($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()]));
|
||||
$form_state->setRedirect(
|
||||
'entity.profile.canonical',
|
||||
['profile' => $this->revision->id()]
|
||||
);
|
||||
if ($this->connection->query('SELECT COUNT(DISTINCT vid) FROM {profile_field_revision} WHERE id = :id', [':id' => $this->revision->id()])->fetchField() > 1) {
|
||||
$form_state->setRedirect(
|
||||
'entity.profile.version_history',
|
||||
['profile' => $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\ProfileInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for reverting a Profile revision.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class ProfileRevisionRevertForm extends ConfirmFormBase {
|
||||
|
||||
|
||||
/**
|
||||
* The Profile revision.
|
||||
*
|
||||
* @var \Drupal\zencrm_entities\Entity\ProfileInterface
|
||||
*/
|
||||
protected $revision;
|
||||
|
||||
/**
|
||||
* The Profile storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $ProfileStorage;
|
||||
|
||||
/**
|
||||
* The date formatter service.
|
||||
*
|
||||
* @var \Drupal\Core\Datetime\DateFormatterInterface
|
||||
*/
|
||||
protected $dateFormatter;
|
||||
|
||||
/**
|
||||
* Constructs a new ProfileRevisionRevertForm.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
|
||||
* The Profile storage.
|
||||
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
|
||||
* The date formatter service.
|
||||
*/
|
||||
public function __construct(EntityStorageInterface $entity_storage, DateFormatterInterface $date_formatter) {
|
||||
$this->ProfileStorage = $entity_storage;
|
||||
$this->dateFormatter = $date_formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager')->getStorage('profile'),
|
||||
$container->get('date.formatter')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'profile_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.profile.version_history', ['profile' => $this->revision->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return t('Revert');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $profile_revision = NULL) {
|
||||
$this->revision = $this->ProfileStorage->loadRevision($profile_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('Profile: reverted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
|
||||
drupal_set_message(t('Profile %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.profile.version_history',
|
||||
['profile' => $this->revision->id()]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a revision to be reverted.
|
||||
*
|
||||
* @param \Drupal\zencrm_entities\Entity\ProfileInterface $revision
|
||||
* The revision to be reverted.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*
|
||||
* @return \Drupal\zencrm_entities\Entity\ProfileInterface
|
||||
* The prepared revision ready to be stored.
|
||||
*/
|
||||
protected function prepareRevertedRevision(ProfileInterface $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\ProfileInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a form for reverting a Profile revision for a single translation.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class ProfileRevisionRevertTranslationForm extends ProfileRevisionRevertForm {
|
||||
|
||||
|
||||
/**
|
||||
* The language to be reverted.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $langcode;
|
||||
|
||||
/**
|
||||
* The language manager.
|
||||
*
|
||||
* @var \Drupal\Core\Language\LanguageManagerInterface
|
||||
*/
|
||||
protected $languageManager;
|
||||
|
||||
/**
|
||||
* Constructs a new ProfileRevisionRevertTranslationForm.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
|
||||
* The Profile 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('profile'),
|
||||
$container->get('date.formatter'),
|
||||
$container->get('language_manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'profile_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, $profile_revision = NULL, $langcode = NULL) {
|
||||
$this->langcode = $langcode;
|
||||
$form = parent::buildForm($form, $form_state, $profile_revision);
|
||||
|
||||
$form['revert_untranslated_fields'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Revert content shared among translations'),
|
||||
'#default_value' => FALSE,
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function prepareRevertedRevision(ProfileInterface $revision, FormStateInterface $form_state) {
|
||||
$revert_untranslated_fields = $form_state->getValue('revert_untranslated_fields');
|
||||
|
||||
/** @var \Drupal\zencrm_entities\Entity\ProfileInterface $default_revision */
|
||||
$latest_revision = $this->ProfileStorage->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;
|
||||
}
|
||||
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class ProfileSettingsForm.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class ProfileSettingsForm extends FormBase {
|
||||
|
||||
/**
|
||||
* Returns a unique string identifying the form.
|
||||
*
|
||||
* @return string
|
||||
* The unique string identifying the form.
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'profile_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 Profile 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['profile_settings']['#markup'] = 'Settings form for Profile entities. Manage field settings here.';
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityConfirmFormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Builds the form to delete Profile type entities.
|
||||
*/
|
||||
class ProfileTypeDeleteForm 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.profile_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());
|
||||
}
|
||||
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class ProfileTypeForm.
|
||||
*/
|
||||
class ProfileTypeForm extends EntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$form = parent::form($form, $form_state);
|
||||
|
||||
$profile_type = $this->entity;
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Label'),
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => $profile_type->label(),
|
||||
'#description' => $this->t("Label for the Profile type."),
|
||||
'#required' => TRUE,
|
||||
];
|
||||
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#default_value' => $profile_type->id(),
|
||||
'#machine_name' => [
|
||||
'exists' => '\Drupal\zencrm_entities\Entity\ProfileType::load',
|
||||
],
|
||||
'#disabled' => !$profile_type->isNew(),
|
||||
];
|
||||
|
||||
/* You will need additional form elements for your custom properties. */
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$profile_type = $this->entity;
|
||||
$status = $profile_type->save();
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
drupal_set_message($this->t('Created the %label Profile type.', [
|
||||
'%label' => $profile_type->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Profile type.', [
|
||||
'%label' => $profile_type->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirectUrl($profile_type->toUrl('collection'));
|
||||
}
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_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 Profile entity.
|
||||
*
|
||||
* @see \Drupal\zencrm_entities\Entity\Profile.
|
||||
*/
|
||||
class ProfileAccessControlHandler extends EntityAccessControlHandler {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
/** @var \Drupal\zencrm_entities\Entity\ProfileInterface $entity */
|
||||
switch ($operation) {
|
||||
case 'view':
|
||||
if (!$entity->isPublished()) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'view unpublished profile entities');
|
||||
}
|
||||
return AccessResult::allowedIfHasPermission($account, 'view published profile entities');
|
||||
|
||||
case 'update':
|
||||
return AccessResult::allowedIfHasPermission($account, 'edit profile entities');
|
||||
|
||||
case 'delete':
|
||||
return AccessResult::allowedIfHasPermission($account, 'delete profile entities');
|
||||
}
|
||||
|
||||
// Unknown operation, no opinion.
|
||||
return AccessResult::neutral();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'add profile entities');
|
||||
}
|
||||
|
||||
}
|
@ -1,196 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Provides routes for Profile entities.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class ProfileHtmlRouteProvider 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\zencrm_entities\Controller\ProfileController::revisionOverview',
|
||||
])
|
||||
->setRequirement('_permission', 'access profile 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\ProfileController::revisionShow',
|
||||
'_title_callback' => '\Drupal\zencrm_entities\Controller\ProfileController::revisionPageTitle',
|
||||
])
|
||||
->setRequirement('_permission', 'access profile 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\ProfileRevisionRevertForm',
|
||||
'_title' => 'Revert to earlier revision',
|
||||
])
|
||||
->setRequirement('_permission', 'revert all profile 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\ProfileRevisionDeleteForm',
|
||||
'_title' => 'Delete earlier revision',
|
||||
])
|
||||
->setRequirement('_permission', 'delete all profile 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\ProfileRevisionRevertTranslationForm',
|
||||
'_title' => 'Revert to earlier revision of a translation',
|
||||
])
|
||||
->setRequirement('_permission', 'revert all profile 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\zencrm_entities\Form\ProfileSettingsForm',
|
||||
'_title' => "{$entity_type->getLabel()} settings",
|
||||
])
|
||||
->setRequirement('_permission', $entity_type->getAdminPermission())
|
||||
->setOption('_admin_route', TRUE);
|
||||
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityListBuilder;
|
||||
use Drupal\Core\Link;
|
||||
|
||||
/**
|
||||
* Defines a class to build a listing of Profile entities.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class ProfileListBuilder extends EntityListBuilder {
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['id'] = $this->t('Profile ID');
|
||||
$header['name'] = $this->t('Name');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
/* @var $entity \Drupal\zencrm_entities\Entity\Profile */
|
||||
$row['id'] = $entity->id();
|
||||
$row['name'] = Link::createFromRoute(
|
||||
$entity->label(),
|
||||
'entity.profile.edit_form',
|
||||
['profile' => $entity->id()]
|
||||
);
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
}
|
@ -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\ProfileInterface;
|
||||
|
||||
/**
|
||||
* Defines the storage handler class for Profile entities.
|
||||
*
|
||||
* This extends the base storage class, adding required special handling for
|
||||
* Profile entities.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class ProfileStorage extends SqlContentEntityStorage implements ProfileStorageInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function revisionIds(ProfileInterface $entity) {
|
||||
return $this->database->query(
|
||||
'SELECT vid FROM {profile_revision} WHERE id=:id ORDER BY vid',
|
||||
[':id' => $entity->id()]
|
||||
)->fetchCol();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function userRevisionIds(AccountInterface $account) {
|
||||
return $this->database->query(
|
||||
'SELECT vid FROM {profile_field_revision} WHERE uid = :uid ORDER BY vid',
|
||||
[':uid' => $account->id()]
|
||||
)->fetchCol();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function countDefaultLanguageRevisions(ProfileInterface $entity) {
|
||||
return $this->database->query('SELECT COUNT(*) FROM {profile_field_revision} WHERE id = :id AND default_langcode = 1', [':id' => $entity->id()])
|
||||
->fetchField();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearRevisionsLanguage(LanguageInterface $language) {
|
||||
return $this->database->update('profile_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\ProfileInterface;
|
||||
|
||||
/**
|
||||
* Defines the storage handler class for Profile entities.
|
||||
*
|
||||
* This extends the base storage class, adding required special handling for
|
||||
* Profile entities.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
interface ProfileStorageInterface extends ContentEntityStorageInterface {
|
||||
|
||||
/**
|
||||
* Gets a list of Profile revision IDs for a specific Profile.
|
||||
*
|
||||
* @param \Drupal\zencrm_entities\Entity\ProfileInterface $entity
|
||||
* The Profile entity.
|
||||
*
|
||||
* @return int[]
|
||||
* Profile revision IDs (in ascending order).
|
||||
*/
|
||||
public function revisionIds(ProfileInterface $entity);
|
||||
|
||||
/**
|
||||
* Gets a list of revision IDs having a given user as Profile author.
|
||||
*
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* The user entity.
|
||||
*
|
||||
* @return int[]
|
||||
* Profile revision IDs (in ascending order).
|
||||
*/
|
||||
public function userRevisionIds(AccountInterface $account);
|
||||
|
||||
/**
|
||||
* Counts the number of revisions in the default language.
|
||||
*
|
||||
* @param \Drupal\zencrm_entities\Entity\ProfileInterface $entity
|
||||
* The Profile entity.
|
||||
*
|
||||
* @return int
|
||||
* The number of revisions in the default language.
|
||||
*/
|
||||
public function countDefaultLanguageRevisions(ProfileInterface $entity);
|
||||
|
||||
/**
|
||||
* Unsets the language for all Profile 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 profile.
|
||||
*/
|
||||
class ProfileTranslationHandler extends ContentTranslationHandler {
|
||||
|
||||
// Override here the needed methods from ContentTranslationHandler.
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Provides routes for Profile type entities.
|
||||
*
|
||||
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class ProfileTypeHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutes(EntityTypeInterface $entity_type) {
|
||||
$collection = parent::getRoutes($entity_type);
|
||||
|
||||
// Provide your custom entity routes here.
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Provides a listing of Profile type entities.
|
||||
*/
|
||||
class ProfileTypeListBuilder extends ConfigEntityListBuilder {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['label'] = $this->t('Profile 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);
|
||||
}
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
{#
|
||||
/**
|
||||
* @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_profile_content_add_list()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
{% spaceless %}
|
||||
<dl>
|
||||
{% for type in types %}
|
||||
<dt>{{ type.link }}</dt>
|
||||
{% endfor %}
|
||||
</dl>
|
||||
{% endspaceless %}
|
@ -1,22 +0,0 @@
|
||||
{#
|
||||
/**
|
||||
* @file profile.html.twig
|
||||
* Default theme implementation to present Profile data.
|
||||
*
|
||||
* This template is used when viewing Profile 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_profile()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
<div{{ attributes.addClass('profile') }}>
|
||||
{% if content %}
|
||||
{{- content -}}
|
||||
{% endif %}
|
||||
</div>
|
Reference in New Issue
Block a user