Added activity entity

This commit is contained in:
naomi 2018-04-14 12:26:09 +02:00
parent 74e98818ba
commit 484fb5a119
25 changed files with 1028 additions and 0 deletions

View File

@ -0,0 +1,30 @@
<?php
/**
* @file
* Contains activity.page.inc.
*
* Page callback for Activity entities.
*/
use Drupal\Core\Render\Element;
/**
* Prepares variables for Activity templates.
*
* Default template: activity.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the user information and any
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_activity(array &$variables) {
// Fetch Activity Entity Object.
$activity = $variables['elements']['#activity'];
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}

View File

@ -0,0 +1,12 @@
zencrm_entities.activity_type.*:
type: config_entity
label: 'Activity type config'
mapping:
id:
type: string
label: 'ID'
label:
type: label
label: 'Label'
uuid:
type: string

View File

@ -0,0 +1,47 @@
<?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 Activity entity.
*
* @see \Drupal\zencrm_entities\Entity\Activity.
*/
class ActivityAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\zencrm_entities\Entity\ActivityInterface $entity */
switch ($operation) {
case 'view':
if (!$entity->isPublished()) {
return AccessResult::allowedIfHasPermission($account, 'view unpublished activity entities');
}
return AccessResult::allowedIfHasPermission($account, 'view published activity entities');
case 'update':
return AccessResult::allowedIfHasPermission($account, 'edit activity entities');
case 'delete':
return AccessResult::allowedIfHasPermission($account, 'delete activity entities');
}
// Unknown operation, no opinion.
return AccessResult::neutral();
}
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'add activity entities');
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace Drupal\zencrm_entities;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
/**
* Provides routes for Activity entities.
*
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
*/
class ActivityHtmlRouteProvider extends AdminHtmlRouteProvider {
/**
* {@inheritdoc}
*/
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);
$entity_type_id = $entity_type->id();
if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
$collection->add("$entity_type_id.settings", $settings_form_route);
}
return $collection;
}
/**
* 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\ActivitySettingsForm',
'_title' => "{$entity_type->getLabel()} settings",
])
->setRequirement('_permission', $entity_type->getAdminPermission())
->setOption('_admin_route', TRUE);
return $route;
}
}
}

View File

@ -0,0 +1,40 @@
<?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 Activity entities.
*
* @ingroup zencrm_entities
*/
class ActivityListBuilder extends EntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['id'] = $this->t('Activity ID');
$header['name'] = $this->t('Name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\zencrm_entities\Entity\Activity */
$row['id'] = $entity->id();
$row['name'] = Link::createFromRoute(
$entity->label(),
'entity.activity.edit_form',
['activity' => $entity->id()]
);
return $row + parent::buildRow($entity);
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace Drupal\zencrm_entities;
use Drupal\content_translation\ContentTranslationHandler;
/**
* Defines the translation handler for activity.
*/
class ActivityTranslationHandler extends ContentTranslationHandler {
// Override here the needed methods from ContentTranslationHandler.
}

View File

@ -0,0 +1,28 @@
<?php
namespace Drupal\zencrm_entities;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
/**
* Provides routes for Activity type entities.
*
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
*/
class ActivityTypeHtmlRouteProvider extends AdminHtmlRouteProvider {
/**
* {@inheritdoc}
*/
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);
// Provide your custom entity routes here.
return $collection;
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Drupal\zencrm_entities;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
/**
* Provides a listing of Activity type entities.
*/
class ActivityTypeListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = $this->t('Activity type');
$header['id'] = $this->t('Machine name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity->label();
$row['id'] = $entity->id();
// You probably want a few more properties here...
return $row + parent::buildRow($entity);
}
}

View File

@ -0,0 +1,224 @@
<?php
namespace Drupal\zencrm_entities\Entity;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\user\UserInterface;
/**
* Defines the Activity entity.
*
* @ingroup zencrm_entities
*
* @ContentEntityType(
* id = "activity",
* label = @Translation("Activity"),
* bundle_label = @Translation("Activity type"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\zencrm_entities\ActivityListBuilder",
* "views_data" = "Drupal\zencrm_entities\Entity\ActivityViewsData",
* "translation" = "Drupal\zencrm_entities\ActivityTranslationHandler",
*
* "form" = {
* "default" = "Drupal\zencrm_entities\Form\ActivityForm",
* "add" = "Drupal\zencrm_entities\Form\ActivityForm",
* "edit" = "Drupal\zencrm_entities\Form\ActivityForm",
* "delete" = "Drupal\zencrm_entities\Form\ActivityDeleteForm",
* },
* "access" = "Drupal\zencrm_entities\ActivityAccessControlHandler",
* "route_provider" = {
* "html" = "Drupal\zencrm_entities\ActivityHtmlRouteProvider",
* },
* },
* base_table = "activity",
* data_table = "activity_field_data",
* translatable = TRUE,
* admin_permission = "administer activity entities",
* entity_keys = {
* "id" = "id",
* "bundle" = "type",
* "label" = "name",
* "uuid" = "uuid",
* "uid" = "user_id",
* "langcode" = "langcode",
* "status" = "status",
* },
* links = {
* "canonical" = "/zencrm/activity/{activity}",
* "add-page" = "/zencrm/activity/add",
* "add-form" = "/zencrm/activity/add/{activity_type}",
* "edit-form" = "/zencrm/activity/{activity}/edit",
* "delete-form" = "/zencrm/activity/{activity}/delete",
* "collection" = "/zencrm/activity",
* },
* bundle_entity_type = "activity_type",
* field_ui_base_route = "entity.activity_type.edit_form"
* )
*/
class Activity extends ContentEntityBase implements ActivityInterface {
use EntityChangedTrait;
/**
* {@inheritdoc}
*/
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
$values += [
'user_id' => \Drupal::currentUser()->id(),
];
}
/**
* {@inheritdoc}
*/
public function getName() {
return $this->get('name')->value;
}
/**
* {@inheritdoc}
*/
public function setName($name) {
$this->set('name', $name);
return $this;
}
/**
* {@inheritdoc}
*/
public function getCreatedTime() {
return $this->get('created')->value;
}
/**
* {@inheritdoc}
*/
public function setCreatedTime($timestamp) {
$this->set('created', $timestamp);
return $this;
}
/**
* {@inheritdoc}
*/
public function getOwner() {
return $this->get('user_id')->entity;
}
/**
* {@inheritdoc}
*/
public function getOwnerId() {
return $this->get('user_id')->target_id;
}
/**
* {@inheritdoc}
*/
public function setOwnerId($uid) {
$this->set('user_id', $uid);
return $this;
}
/**
* {@inheritdoc}
*/
public function setOwner(UserInterface $account) {
$this->set('user_id', $account->id());
return $this;
}
/**
* {@inheritdoc}
*/
public function isPublished() {
return (bool) $this->getEntityKey('status');
}
/**
* {@inheritdoc}
*/
public function setPublished($published) {
$this->set('status', $published ? TRUE : FALSE);
return $this;
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Authored by'))
->setDescription(t('The user ID of author of the Activity entity.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
# ->setDisplayOptions('view', [
# 'label' => 'hidden',
# 'type' => 'author',
# 'weight' => 0,
# ])
# ->setDisplayOptions('form', [
# 'type' => 'entity_reference_autocomplete',
# 'weight' => 5,
# 'settings' => [
# 'match_operator' => 'CONTAINS',
# 'size' => '60',
# 'autocomplete_type' => 'tags',
# 'placeholder' => '',
# ],
# ])
# ->setDisplayConfigurable('form', TRUE)
# ->setDisplayConfigurable('view', TRUE);
->setTranslatable(TRUE);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the Activity entity.'))
->setSettings([
'max_length' => 50,
'text_processing' => 0,
])
->setDefaultValue('')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => -4,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -4,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);
$fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Publishing status'))
->setDescription(t('A boolean indicating whether the Activity is published.'))
->setDefaultValue(TRUE)
->setDisplayOptions('form', [
'type' => 'boolean_checkbox',
'weight' => -3,
]);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the entity was last edited.'));
return $fields;
}
}

View File

@ -0,0 +1,77 @@
<?php
namespace Drupal\zencrm_entities\Entity;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\user\EntityOwnerInterface;
/**
* Provides an interface for defining Activity entities.
*
* @ingroup zencrm_entities
*/
interface ActivityInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface {
// Add get/set methods for your configuration properties here.
/**
* Gets the Activity name.
*
* @return string
* Name of the Activity.
*/
public function getName();
/**
* Sets the Activity name.
*
* @param string $name
* The Activity name.
*
* @return \Drupal\zencrm_entities\Entity\ActivityInterface
* The called Activity entity.
*/
public function setName($name);
/**
* Gets the Activity creation timestamp.
*
* @return int
* Creation timestamp of the Activity.
*/
public function getCreatedTime();
/**
* Sets the Activity creation timestamp.
*
* @param int $timestamp
* The Activity creation timestamp.
*
* @return \Drupal\zencrm_entities\Entity\ActivityInterface
* The called Activity entity.
*/
public function setCreatedTime($timestamp);
/**
* Returns the Activity published status indicator.
*
* Unpublished Activity are only visible to restricted users.
*
* @return bool
* TRUE if the Activity is published.
*/
public function isPublished();
/**
* Sets the published status of a Activity.
*
* @param bool $published
* TRUE to set this Activity to published, FALSE to set it to unpublished.
*
* @return \Drupal\zencrm_entities\Entity\ActivityInterface
* The called Activity entity.
*/
public function setPublished($published);
}

View File

@ -0,0 +1,58 @@
<?php
namespace Drupal\zencrm_entities\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
/**
* Defines the Activity type entity.
*
* @ConfigEntityType(
* id = "activity_type",
* label = @Translation("Activity type"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\zencrm_entities\ActivityTypeListBuilder",
* "form" = {
* "add" = "Drupal\zencrm_entities\Form\ActivityTypeForm",
* "edit" = "Drupal\zencrm_entities\Form\ActivityTypeForm",
* "delete" = "Drupal\zencrm_entities\Form\ActivityTypeDeleteForm"
* },
* "route_provider" = {
* "html" = "Drupal\zencrm_entities\ActivityTypeHtmlRouteProvider",
* },
* },
* config_prefix = "activity_type",
* admin_permission = "administer site configuration",
* bundle_of = "activity",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* },
* links = {
* "canonical" = "/zencrm/activity_type/{activity_type}",
* "add-form" = "/zencrm/activity_type/add",
* "edit-form" = "/zencrm/activity_type/{activity_type}/edit",
* "delete-form" = "/zencrm/activity_type/{activity_type}/delete",
* "collection" = "/zencrm/activity_type"
* }
* )
*/
class ActivityType extends ConfigEntityBundleBase implements ActivityTypeInterface {
/**
* The Activity type ID.
*
* @var string
*/
protected $id;
/**
* The Activity type label.
*
* @var string
*/
protected $label;
}

View File

@ -0,0 +1,13 @@
<?php
namespace Drupal\zencrm_entities\Entity;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides an interface for defining Activity type entities.
*/
interface ActivityTypeInterface extends ConfigEntityInterface {
// Add get/set methods for your configuration properties here.
}

View File

@ -0,0 +1,24 @@
<?php
namespace Drupal\zencrm_entities\Entity;
use Drupal\views\EntityViewsData;
/**
* Provides Views data for Activity entities.
*/
class ActivityViewsData extends EntityViewsData {
/**
* {@inheritdoc}
*/
public function getViewsData() {
$data = parent::getViewsData();
// Additional information for Views integration, such as table joins, can be
// put here.
return $data;
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace Drupal\zencrm_entities\Form;
use Drupal\Core\Entity\ContentEntityDeleteForm;
/**
* Provides a form for deleting Activity entities.
*
* @ingroup zencrm_entities
*/
class ActivityDeleteForm extends ContentEntityDeleteForm {
}

View File

@ -0,0 +1,50 @@
<?php
namespace Drupal\zencrm_entities\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
/**
* Form controller for Activity edit forms.
*
* @ingroup zencrm_entities
*/
class ActivityForm extends ContentEntityForm {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/* @var $entity \Drupal\zencrm_entities\Entity\Activity */
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity;
$status = parent::save($form, $form_state);
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created the %label Activity.', [
'%label' => $entity->label(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label Activity.', [
'%label' => $entity->label(),
]));
}
$form_state->setRedirect('entity.activity.canonical', ['activity' => $entity->id()]);
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace Drupal\zencrm_entities\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Class ActivitySettingsForm.
*
* @ingroup zencrm_entities
*/
class ActivitySettingsForm extends FormBase {
/**
* Returns a unique string identifying the form.
*
* @return string
* The unique string identifying the form.
*/
public function getFormId() {
return 'activity_settings';
}
/**
* Form submission handler.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Empty implementation of the abstract submit class.
}
/**
* Defines the settings form for Activity entities.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array
* Form definition array.
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['activity_settings']['#markup'] = 'Settings form for Activity entities. Manage field settings here.';
return $form;
}
}

View File

@ -0,0 +1,53 @@
<?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 Activity type entities.
*/
class ActivityTypeDeleteForm 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.activity_type.collection');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message(
$this->t('content @type: deleted @label.',
[
'@type' => $this->entity->bundle(),
'@label' => $this->entity->label(),
]
)
);
$form_state->setRedirectUrl($this->getCancelUrl());
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace Drupal\zencrm_entities\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
/**
* Class ActivityTypeForm.
*/
class ActivityTypeForm extends EntityForm {
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$activity_type = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#maxlength' => 255,
'#default_value' => $activity_type->label(),
'#description' => $this->t("Label for the Activity type."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $activity_type->id(),
'#machine_name' => [
'exists' => '\Drupal\zencrm_entities\Entity\ActivityType::load',
],
'#disabled' => !$activity_type->isNew(),
];
/* You will need additional form elements for your custom properties. */
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$activity_type = $this->entity;
$status = $activity_type->save();
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created the %label Activity type.', [
'%label' => $activity_type->label(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label Activity type.', [
'%label' => $activity_type->label(),
]));
}
$form_state->setRedirectUrl($activity_type->toUrl('collection'));
}
}

View File

@ -0,0 +1,23 @@
{#
/**
* @file
* Default theme implementation to present a list of custom content entity types/bundles.
*
* Available variables:
* - types: A collection of all the available custom entity types/bundles.
* Each type/bundle contains the following:
* - link: A link to add a content entity of this type.
* - description: A description of this content entity types/bundle.
*
* @see template_preprocess_activity_content_add_list()
*
* @ingroup themeable
*/
#}
{% spaceless %}
<dl>
{% for type in types %}
<dt>{{ type.link }}</dt>
{% endfor %}
</dl>
{% endspaceless %}

View File

@ -0,0 +1,22 @@
{#
/**
* @file activity.html.twig
* Default theme implementation to present Activity data.
*
* This template is used when viewing Activity pages.
*
*
* Available variables:
* - content: A list of content items. Use 'content' to print all content, or
* - attributes: HTML attributes for the container element.
*
* @see template_preprocess_activity()
*
* @ingroup themeable
*/
#}
<div{{ attributes.addClass('activity') }}>
{% if content %}
{{- content -}}
{% endif %}
</div>

View File

@ -41,3 +41,14 @@ entity.case_entity_type.add_form:
appears_on:
- entity.case_entity_type.collection
entity.activity.add_form:
route_name: entity.activity.add_page
title: 'Add Activity'
appears_on:
- entity.activity.collection
entity.activity_type.add_form:
route_name: entity.activity_type.add_form
title: 'Add Activity type'
appears_on:
- entity.activity_type.collection

View File

@ -90,3 +90,21 @@ entity.case_entity_type.collection:
parent: system.admin_structure
weight: 99
# Activity menu items definition
entity.activity.collection:
title: 'Activity list'
route_name: entity.activity.collection
description: 'List Activity entities'
parent: system.admin_structure
weight: 100
# Activity type menu items definition
entity.activity_type.collection:
title: 'Activity type'
route_name: entity.activity_type.collection
description: 'List Activity type (bundles)'
parent: system.admin_structure
weight: 99

View File

@ -122,3 +122,21 @@ entity.case_entity.delete_form:
title: Delete
weight: 10
# Activity routing definition
entity.activity.canonical:
route_name: entity.activity.canonical
base_route: entity.activity.canonical
title: 'View'
entity.activity.edit_form:
route_name: entity.activity.edit_form
base_route: entity.activity.canonical
title: 'Edit'
entity.activity.delete_form:
route_name: entity.activity.delete_form
base_route: entity.activity.canonical
title: Delete
weight: 10

View File

@ -81,6 +81,16 @@ function zencrm_entities_theme() {
'variables' => ['content' => NULL],
'file' => 'case_entity.page.inc',
];
$theme['activity'] = [
'render element' => 'elements',
'file' => 'activity.page.inc',
'template' => 'activity',
];
$theme['activity_content_add_list'] = [
'render element' => 'content',
'variables' => ['content' => NULL],
'file' => 'activity.page.inc',
];
return $theme;
}
@ -115,3 +125,19 @@ function zencrm_entities_theme_suggestions_case_entity(array $variables) {
$suggestions[] = 'case_entity__' . $entity->id() . '__' . $sanitized_view_mode;
return $suggestions;
}
/**
* Implements hook_theme_suggestions_HOOK().
*/
function zencrm_entities_theme_suggestions_activity(array $variables) {
$suggestions = [];
$entity = $variables['elements']['#activity'];
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
$suggestions[] = 'activity__' . $sanitized_view_mode;
$suggestions[] = 'activity__' . $entity->bundle();
$suggestions[] = 'activity__' . $entity->bundle() . '__' . $sanitized_view_mode;
$suggestions[] = 'activity__' . $entity->id();
$suggestions[] = 'activity__' . $entity->id() . '__' . $sanitized_view_mode;
return $suggestions;
}

View File

@ -135,3 +135,22 @@ view published case entity entities:
view unpublished case entity entities:
title: 'View unpublished Case entity entities'
add activity entities:
title: 'Create new Activity entities'
administer activity entities:
title: 'Administer Activity entities'
description: 'Allow to access the administration form to configure Activity entities.'
restrict access: true
delete activity entities:
title: 'Delete Activity entities'
edit activity entities:
title: 'Edit Activity entities'
view published activity entities:
title: 'View published Activity entities'
view unpublished activity entities:
title: 'View unpublished Activity entities'