created edlp_studio module, only with chutier and fil entities definitions

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-10 17:19:45 +01:00
parent 7e564374c7
commit 7d2a7f4f37
33 changed files with 1574 additions and 0 deletions
@@ -0,0 +1,30 @@
<?php
/**
* @file
* Contains chutier.page.inc.
*
* Page callback for Chutier entities.
*/
use Drupal\Core\Render\Element;
/**
* Prepares variables for Chutier templates.
*
* Default template: chutier.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_chutier(array &$variables) {
// Fetch Chutier Entity Object.
$chutier = $variables['elements']['#chutier'];
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
@@ -0,0 +1,7 @@
name: 'Edlp Studio'
type: module
description: 'Edlp module that handle chutier and fils entities'
core: 8.x
package: 'edlp'
dependencies:
- entity_reference
@@ -0,0 +1,10 @@
entity.chutier.add_form:
route_name: entity.chutier.add_form
title: 'Add Chutier'
appears_on:
- entity.chutier.collection
entity.fil.add_form:
route_name: entity.fil.add_form
title: 'Add Fil'
appears_on:
- entity.fil.collection
@@ -0,0 +1,34 @@
edlp_studio.studio:
title: 'Studio'
route_name: edlp_studio.studio
description: 'Edlp Studio configurations'
parent: system.admin_structure
weight: 100
# Chutier menu items definition
entity.chutier.collection:
title: 'Chutier list'
route_name: entity.chutier.collection
description: 'List Chutier entities'
parent: edlp_studio.studio
weight: 100
chutier.admin.structure.settings:
title: 'Chutier settings'
description: 'Configure Chutier entities'
route_name: chutier.settings
parent: edlp_studio.studio
# Fil menu items definition
entity.fil.collection:
title: 'Fil list'
route_name: entity.fil.collection
description: 'List Fil entities'
parent: edlp_studio.studio
weight: 100
fil.admin.structure.settings:
title: 'Fil settings'
description: 'Configure Fil entities'
route_name: fil.settings
parent: edlp_studio.studio
@@ -0,0 +1,43 @@
# Chutier routing definition
chutier.settings_tab:
route_name: chutier.settings
title: 'Settings'
base_route: chutier.settings
entity.chutier.canonical:
route_name: entity.chutier.canonical
base_route: entity.chutier.canonical
title: 'View'
entity.chutier.edit_form:
route_name: entity.chutier.edit_form
base_route: entity.chutier.canonical
title: 'Edit'
entity.chutier.delete_form:
route_name: entity.chutier.delete_form
base_route: entity.chutier.canonical
title: Delete
weight: 10
# Fil routing definition
fil.settings_tab:
route_name: fil.settings
title: 'Settings'
base_route: fil.settings
entity.fil.canonical:
route_name: entity.fil.canonical
base_route: entity.fil.canonical
title: 'View'
entity.fil.edit_form:
route_name: entity.fil.edit_form
base_route: entity.fil.canonical
title: 'Edit'
entity.fil.delete_form:
route_name: entity.fil.delete_form
base_route: entity.fil.canonical
title: Delete
weight: 10
@@ -0,0 +1,24 @@
<?php
/**
* @file
* Contains edlp_studio.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function edlp_studio_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the edlp_studio module.
case 'help.page.edlp_studio':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Edlp module that handle chutier and fils entities') . '</p>';
return $output;
default:
}
}
@@ -0,0 +1,62 @@
administer studio:
title: 'Administer studio'
# Chutiers
add chutier entities:
title: 'Create new Chutier entities'
administer chutier entities:
title: 'Administer Chutier entities'
description: 'Allow to access the administration form to configure Chutier entities.'
restrict access: true
delete any chutier entities:
title: 'Delete any Chutier entities'
edit any chutier entities:
title: 'Edit any Chutier entities'
delete own chutier entities:
title: 'Delete own Chutier entities'
edit own chutier entities:
title: 'Edit own Chutier entities'
view published chutier entities:
title: 'View published Chutier entities'
view any unpublished chutier entities:
title: 'View any unpublished Chutier entities'
view own unpublished chutier entities:
title: 'View own unpublished Chutier entities'
# Fils
add fil entities:
title: 'Create new Fil entities'
administer fil entities:
title: 'Administer Fil entities'
description: 'Allow to access the administration form to configure Fil entities.'
restrict access: true
delete any fil entities:
title: 'Delete any Fil entities'
edit any fil entities:
title: 'Edit any Fil entities'
delete own fil entities:
title: 'Delete own Fil entities'
edit own fil entities:
title: 'Edit own Fil entities'
view published fil entities:
title: 'View published Fil entities'
view any unpublished fil entities:
title: 'View any unpublished Fil entities'
view own unpublished fil entities:
title: 'View own unpublished Fil entities'
@@ -0,0 +1,7 @@
edlp_studio.studio:
path: '/admin/structure/studio'
defaults:
_controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
_title: 'Studio'
requirements:
_permission: 'administer studio'
@@ -0,0 +1,30 @@
<?php
/**
* @file
* Contains fil.page.inc.
*
* Page callback for Fil entities.
*/
use Drupal\Core\Render\Element;
/**
* Prepares variables for Fil templates.
*
* Default template: fil.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_fil(array &$variables) {
// Fetch Fil Entity Object.
$fil = $variables['elements']['#fil'];
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
@@ -0,0 +1,59 @@
<?php
namespace Drupal\edlp_studio;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
/**
* Access controller for the Chutier entity.
*
* @see \Drupal\edlp_studio\Entity\Chutier.
*/
class ChutierAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\edlp_studio\Entity\ChutierInterface $entity */
switch ($operation) {
case 'view':
if (!$entity->isPublished()) {
if($account->hasPermission('view own unpublished chutier entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
}else{
return AccessResult::allowedIfHasPermission($account, 'view any unpublished chutier entities');
}
}
return AccessResult::allowedIfHasPermission($account, 'view published chutier entities');
case 'update':
if($account->hasPermission('edit own chutier entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
}else{
return AccessResult::allowedIfHasPermission($account, 'edit any chutier entities');
}
case 'delete':
if($account->hasPermission('delete own chutier entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
}else{
return AccessResult::allowedIfHasPermission($account, 'delete chutier entities');
}
}
// Unknown operation, no opinion.
return AccessResult::neutral();
}
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'add chutier entities');
}
}
@@ -0,0 +1,56 @@
<?php
namespace Drupal\edlp_studio;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
/**
* Provides routes for Chutier entities.
*
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
*/
class ChutierHtmlRouteProvider 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\edlp_studio\Form\ChutierSettingsForm',
'_title' => "{$entity_type->getLabel()} settings",
])
->setRequirement('_permission', $entity_type->getAdminPermission())
->setOption('_admin_route', TRUE);
return $route;
}
}
}
@@ -0,0 +1,40 @@
<?php
namespace Drupal\edlp_studio;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Link;
/**
* Defines a class to build a listing of Chutier entities.
*
* @ingroup edlp_studio
*/
class ChutierListBuilder extends EntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['id'] = $this->t('Chutier ID');
$header['name'] = $this->t('Name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\edlp_studio\Entity\Chutier */
$row['id'] = $entity->id();
$row['name'] = Link::createFromRoute(
$entity->label(),
'entity.chutier.edit_form',
['chutier' => $entity->id()]
);
return $row + parent::buildRow($entity);
}
}
@@ -0,0 +1,242 @@
<?php
namespace Drupal\edlp_studio\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 Chutier entity.
*
* @ingroup edlp_studio
*
* @ContentEntityType(
* id = "chutier",
* label = @Translation("Chutier"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\edlp_studio\ChutierListBuilder",
* "views_data" = "Drupal\edlp_studio\Entity\ChutierViewsData",
*
* "form" = {
* "default" = "Drupal\edlp_studio\Form\ChutierForm",
* "add" = "Drupal\edlp_studio\Form\ChutierForm",
* "edit" = "Drupal\edlp_studio\Form\ChutierForm",
* "delete" = "Drupal\edlp_studio\Form\ChutierDeleteForm",
* },
* "access" = "Drupal\edlp_studio\ChutierAccessControlHandler",
* "route_provider" = {
* "html" = "Drupal\edlp_studio\ChutierHtmlRouteProvider",
* },
* },
* base_table = "chutier",
* admin_permission = "administer chutier entities",
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* "uid" = "user_id",
* "langcode" = "langcode",
* "status" = "status",
* },
* links = {
* "canonical" = "/admin/structure/studio/chutier/{chutier}",
* "add-form" = "/admin/structure/studio/chutier/add",
* "edit-form" = "/admin/structure/studio/chutier/{chutier}/edit",
* "delete-form" = "/admin/structure/studio/chutier/{chutier}/delete",
* "collection" = "/admin/structure/studio/chutier",
* },
* field_ui_base_route = "chutier.settings"
* )
*/
class Chutier extends ContentEntityBase implements ChutierInterface {
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 Chutier entity.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'author',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the Chutier 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 Chutier 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.'));
$fields['documents'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Documents'))
->setDescription(t('Documents from collection.'))
->setSetting('target_type', 'node')
->setSetting('handler', 'default')
->setSetting('handler_settings',['target_bundles'=>['enregistrement'=>'enregistrement']] )
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', array(
'label' => 'hidden',
'type' => 'enregistrement',
'weight' => 0,
))
->setDisplayOptions('form', array(
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
),
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
return $fields;
}
}
@@ -0,0 +1,77 @@
<?php
namespace Drupal\edlp_studio\Entity;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\user\EntityOwnerInterface;
/**
* Provides an interface for defining Chutier entities.
*
* @ingroup edlp_studio
*/
interface ChutierInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface {
// Add get/set methods for your configuration properties here.
/**
* Gets the Chutier name.
*
* @return string
* Name of the Chutier.
*/
public function getName();
/**
* Sets the Chutier name.
*
* @param string $name
* The Chutier name.
*
* @return \Drupal\edlp_studio\Entity\ChutierInterface
* The called Chutier entity.
*/
public function setName($name);
/**
* Gets the Chutier creation timestamp.
*
* @return int
* Creation timestamp of the Chutier.
*/
public function getCreatedTime();
/**
* Sets the Chutier creation timestamp.
*
* @param int $timestamp
* The Chutier creation timestamp.
*
* @return \Drupal\edlp_studio\Entity\ChutierInterface
* The called Chutier entity.
*/
public function setCreatedTime($timestamp);
/**
* Returns the Chutier published status indicator.
*
* Unpublished Chutier are only visible to restricted users.
*
* @return bool
* TRUE if the Chutier is published.
*/
public function isPublished();
/**
* Sets the published status of a Chutier.
*
* @param bool $published
* TRUE to set this Chutier to published, FALSE to set it to unpublished.
*
* @return \Drupal\edlp_studio\Entity\ChutierInterface
* The called Chutier entity.
*/
public function setPublished($published);
}
@@ -0,0 +1,24 @@
<?php
namespace Drupal\edlp_studio\Entity;
use Drupal\views\EntityViewsData;
/**
* Provides Views data for Chutier entities.
*/
class ChutierViewsData extends EntityViewsData {
/**
* {@inheritdoc}
*/
public function getViewsData() {
$data = parent::getViewsData();
// Additional information for Views integration, such as table joins, can be
// put here.
return $data;
}
}
@@ -0,0 +1,243 @@
<?php
namespace Drupal\edlp_studio\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 Fil entity.
*
* @ingroup edlp_studio
*
* @ContentEntityType(
* id = "fil",
* label = @Translation("Fil"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\edlp_studio\FilListBuilder",
* "views_data" = "Drupal\edlp_studio\Entity\FilViewsData",
*
* "form" = {
* "default" = "Drupal\edlp_studio\Form\FilForm",
* "add" = "Drupal\edlp_studio\Form\FilForm",
* "edit" = "Drupal\edlp_studio\Form\FilForm",
* "delete" = "Drupal\edlp_studio\Form\FilDeleteForm",
* },
* "access" = "Drupal\edlp_studio\FilAccessControlHandler",
* "route_provider" = {
* "html" = "Drupal\edlp_studio\FilHtmlRouteProvider",
* },
* },
* base_table = "fil",
* admin_permission = "administer fil entities",
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* "uid" = "user_id",
* "langcode" = "langcode",
* "status" = "status",
* },
* links = {
* "canonical" = "/admin/structure/studio/fil/{fil}",
* "add-form" = "/admin/structure/studio/fil/add",
* "edit-form" = "/admin/structure/studio/fil/{fil}/edit",
* "delete-form" = "/admin/structure/studio/fil/{fil}/delete",
* "collection" = "/admin/structure/studio/fil",
* },
* field_ui_base_route = "fil.settings"
* )
*/
class Fil extends ContentEntityBase implements FilInterface {
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 Fil entity.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'author',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the Fil 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 Fil 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.'));
$fields['documents'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Documents'))
->setDescription(t('Documents from collection.'))
->setSetting('target_type', 'node')
->setSetting('handler', 'default')
->setSetting('handler_settings',['target_bundles'=>['enregistrement'=>'enregistrement']] )
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', array(
'label' => 'hidden',
'type' => 'enregistrement',
'weight' => 0,
))
->setDisplayOptions('form', array(
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
),
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
return $fields;
}
}
@@ -0,0 +1,77 @@
<?php
namespace Drupal\edlp_studio\Entity;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\user\EntityOwnerInterface;
/**
* Provides an interface for defining Fil entities.
*
* @ingroup edlp_studio
*/
interface FilInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface {
// Add get/set methods for your configuration properties here.
/**
* Gets the Fil name.
*
* @return string
* Name of the Fil.
*/
public function getName();
/**
* Sets the Fil name.
*
* @param string $name
* The Fil name.
*
* @return \Drupal\edlp_studio\Entity\FilInterface
* The called Fil entity.
*/
public function setName($name);
/**
* Gets the Fil creation timestamp.
*
* @return int
* Creation timestamp of the Fil.
*/
public function getCreatedTime();
/**
* Sets the Fil creation timestamp.
*
* @param int $timestamp
* The Fil creation timestamp.
*
* @return \Drupal\edlp_studio\Entity\FilInterface
* The called Fil entity.
*/
public function setCreatedTime($timestamp);
/**
* Returns the Fil published status indicator.
*
* Unpublished Fil are only visible to restricted users.
*
* @return bool
* TRUE if the Fil is published.
*/
public function isPublished();
/**
* Sets the published status of a Fil.
*
* @param bool $published
* TRUE to set this Fil to published, FALSE to set it to unpublished.
*
* @return \Drupal\edlp_studio\Entity\FilInterface
* The called Fil entity.
*/
public function setPublished($published);
}
@@ -0,0 +1,24 @@
<?php
namespace Drupal\edlp_studio\Entity;
use Drupal\views\EntityViewsData;
/**
* Provides Views data for Fil entities.
*/
class FilViewsData extends EntityViewsData {
/**
* {@inheritdoc}
*/
public function getViewsData() {
$data = parent::getViewsData();
// Additional information for Views integration, such as table joins, can be
// put here.
return $data;
}
}
@@ -0,0 +1,59 @@
<?php
namespace Drupal\edlp_studio;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
/**
* Access controller for the Fil entity.
*
* @see \Drupal\edlp_studio\Entity\Fil.
*/
class FilAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\edlp_studio\Entity\FilInterface $entity */
switch ($operation) {
case 'view':
if (!$entity->isPublished()) {
if($account->hasPermission('view own unpublished fil entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
}else{
return AccessResult::allowedIfHasPermission($account, 'view any unpublished fil entities');
}
}
return AccessResult::allowedIfHasPermission($account, 'view published fil entities');
case 'update':
if($account->hasPermission('edit own fil entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
}else{
return AccessResult::allowedIfHasPermission($account, 'edit any fil entities');
}
case 'delete':
if($account->hasPermission('delete own fil entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
}else{
return AccessResult::allowedIfHasPermission($account, 'delete fil entities');
}
}
// Unknown operation, no opinion.
return AccessResult::neutral();
}
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'add fil entities');
}
}
@@ -0,0 +1,56 @@
<?php
namespace Drupal\edlp_studio;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
/**
* Provides routes for Fil entities.
*
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
*/
class FilHtmlRouteProvider 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/studio/{$entity_type->id()}/settings");
$route
->setDefaults([
'_form' => 'Drupal\edlp_studio\Form\FilSettingsForm',
'_title' => "{$entity_type->getLabel()} settings",
])
->setRequirement('_permission', $entity_type->getAdminPermission())
->setOption('_admin_route', TRUE);
return $route;
}
}
}
@@ -0,0 +1,40 @@
<?php
namespace Drupal\edlp_studio;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Link;
/**
* Defines a class to build a listing of Fil entities.
*
* @ingroup edlp_studio
*/
class FilListBuilder extends EntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['id'] = $this->t('Fil ID');
$header['name'] = $this->t('Name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\edlp_studio\Entity\Fil */
$row['id'] = $entity->id();
$row['name'] = Link::createFromRoute(
$entity->label(),
'entity.fil.edit_form',
['fil' => $entity->id()]
);
return $row + parent::buildRow($entity);
}
}
@@ -0,0 +1,15 @@
<?php
namespace Drupal\edlp_studio\Form;
use Drupal\Core\Entity\ContentEntityDeleteForm;
/**
* Provides a form for deleting Chutier entities.
*
* @ingroup edlp_studio
*/
class ChutierDeleteForm extends ContentEntityDeleteForm {
}
@@ -0,0 +1,50 @@
<?php
namespace Drupal\edlp_studio\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
/**
* Form controller for Chutier edit forms.
*
* @ingroup edlp_studio
*/
class ChutierForm extends ContentEntityForm {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/* @var $entity \Drupal\edlp_studio\Entity\Chutier */
$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 Chutier.', [
'%label' => $entity->label(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label Chutier.', [
'%label' => $entity->label(),
]));
}
$form_state->setRedirect('entity.chutier.canonical', ['chutier' => $entity->id()]);
}
}
@@ -0,0 +1,53 @@
<?php
namespace Drupal\edlp_studio\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Class ChutierSettingsForm.
*
* @ingroup edlp_studio
*/
class ChutierSettingsForm extends FormBase {
/**
* Returns a unique string identifying the form.
*
* @return string
* The unique string identifying the form.
*/
public function getFormId() {
return 'chutier_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 Chutier 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['chutier_settings']['#markup'] = 'Settings form for Chutier entities. Manage field settings here.';
return $form;
}
}
@@ -0,0 +1,15 @@
<?php
namespace Drupal\edlp_studio\Form;
use Drupal\Core\Entity\ContentEntityDeleteForm;
/**
* Provides a form for deleting Fil entities.
*
* @ingroup edlp_studio
*/
class FilDeleteForm extends ContentEntityDeleteForm {
}
@@ -0,0 +1,50 @@
<?php
namespace Drupal\edlp_studio\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
/**
* Form controller for Fil edit forms.
*
* @ingroup edlp_studio
*/
class FilForm extends ContentEntityForm {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/* @var $entity \Drupal\edlp_studio\Entity\Fil */
$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 Fil.', [
'%label' => $entity->label(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label Fil.', [
'%label' => $entity->label(),
]));
}
$form_state->setRedirect('entity.fil.canonical', ['fil' => $entity->id()]);
}
}
@@ -0,0 +1,53 @@
<?php
namespace Drupal\edlp_studio\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Class FilSettingsForm.
*
* @ingroup edlp_studio
*/
class FilSettingsForm extends FormBase {
/**
* Returns a unique string identifying the form.
*
* @return string
* The unique string identifying the form.
*/
public function getFormId() {
return 'fil_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 Fil 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['fil_settings']['#markup'] = 'Settings form for Fil entities. Manage field settings here.';
return $form;
}
}
@@ -0,0 +1,22 @@
{#
/**
* @file chutier.html.twig
* Default theme implementation to present Chutier data.
*
* This template is used when viewing Chutier 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_chutier()
*
* @ingroup themeable
*/
#}
<div{{ attributes.addClass('chutier') }}>
{% if content %}
{{- content -}}
{% endif %}
</div>
@@ -0,0 +1,22 @@
{#
/**
* @file fil.html.twig
* Default theme implementation to present Fil data.
*
* This template is used when viewing Fil 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_fil()
*
* @ingroup themeable
*/
#}
<div{{ attributes.addClass('fil') }}>
{% if content %}
{{- content -}}
{% endif %}
</div>
@@ -34,7 +34,9 @@ module:
edlp_home: 0
edlp_migrate: 0
edlp_productions: 0
edlp_studio: 0
entity: 0
entity_reference: 0
features: 0
features_ui: 0
field: 0
@@ -14,3 +14,4 @@ permissions:
- 'access kint'
- 'create corpus_documents workflow_transition'
- 'create generique workflow_transition'
- 'view published fil entities'
@@ -12,6 +12,15 @@ permissions:
- 'access content'
- 'access devel information'
- 'access kint'
- 'add chutier entities'
- 'add fil entities'
- 'create corpus_documents workflow_transition'
- 'create generique workflow_transition'
- 'delete own chutier entities'
- 'delete own fil entities'
- 'edit own chutier entities'
- 'edit own fil entities'
- 'use text format wysiwyg'
- 'view own unpublished chutier entities'
- 'view own unpublished fil entities'
- 'view published fil entities'
@@ -13,30 +13,45 @@ permissions:
- 'access content'
- 'access content overview'
- 'access contextual links'
- 'access corpus_documents workflow_transition form'
- 'access devel information'
- 'access files overview'
- 'access generique workflow_transition form'
- 'access inactive domains'
- 'access own corpus_documents workflow_transion overview'
- 'access own generique workflow_transion overview'
- 'access profile overview'
- 'access site in maintenance mode'
- 'access site reports'
- 'access toolbar'
- 'access user profiles'
- 'add chutier entities'
- 'administer account menu items'
- 'administer account settings'
- 'administer actions'
- 'administer admin menu items'
- 'administer blocks'
- 'administer chutier display'
- 'administer chutier entities'
- 'administer chutier fields'
- 'administer chutier form display'
- 'administer content translation'
- 'administer content types'
- 'administer contexts'
- 'administer devel menu items'
- 'administer devel_generate'
- 'administer display modes'
- 'administer domain aliases'
- 'administer domains'
- 'administer fil entities'
- 'administer filters'
- 'administer footer menu items'
- 'administer image styles'
- 'administer languages'
- 'administer linkit profiles'
- 'administer login destination settings'
- 'administer maillog'
- 'administer main menu items'
- 'administer menu'
- 'administer migrations'
- 'administer modules'
@@ -54,11 +69,13 @@ permissions:
- 'administer responsive images'
- 'administer site configuration'
- 'administer software updates'
- 'administer studio'
- 'administer taxonomy'
- 'administer taxonomy_term display'
- 'administer taxonomy_term fields'
- 'administer taxonomy_term form display'
- 'administer themes'
- 'administer tools menu items'
- 'administer url aliases'
- 'administer user display'
- 'administer user fields'
@@ -66,8 +83,12 @@ permissions:
- 'administer users'
- 'administer views'
- 'administer workflow'
- 'administer workflow_transition display'
- 'administer workflow_transition fields'
- 'administer workflow_transition form display'
- 'assign domain administrators'
- 'ban IP addresses'
- 'bulkdelete nodes'
- 'bypass corpus_documents workflow_transition access'
- 'bypass generique workflow_transition access'
- 'bypass node access'
@@ -85,19 +106,24 @@ permissions:
- 'create page content'
- 'create static content'
- 'create url aliases'
- 'delete all fil revisions'
- 'delete all revisions'
- 'delete any autre_son content'
- 'delete any chutier entities'
- 'delete any enregistrement content'
- 'delete any evenement content'
- 'delete any fil content'
- 'delete any fil entities'
- 'delete any page content'
- 'delete any static content'
- 'delete assigned domains'
- 'delete autre_son revisions'
- 'delete chutier entities'
- 'delete content translations'
- 'delete domain aliases'
- 'delete enregistrement revisions'
- 'delete evenement revisions'
- 'delete fil entities'
- 'delete fil revisions'
- 'delete maillog'
- 'delete own autre_son content'
@@ -115,13 +141,17 @@ permissions:
- 'delete terms in locuteurs'
- 'delete terms in page_type'
- 'edit any autre_son content'
- 'edit any chutier entities'
- 'edit any enregistrement content'
- 'edit any evenement content'
- 'edit any fil content'
- 'edit any fil entities'
- 'edit any page content'
- 'edit any static content'
- 'edit assigned domains'
- 'edit chutier entities'
- 'edit domain aliases'
- 'edit fil entities'
- 'edit own autre_son content'
- 'edit own enregistrement content'
- 'edit own evenement content'
@@ -138,6 +168,7 @@ permissions:
- 'export configuration'
- 'import configuration'
- 'link to any page'
- 'revert all fil revisions'
- 'revert all revisions'
- 'revert autre_son revisions'
- 'revert enregistrement revisions'
@@ -159,7 +190,10 @@ permissions:
- 'use domain nav block'
- 'use domain switcher block'
- 'use text format wysiwyg'
- 'view all fil revisions'
- 'view all revisions'
- 'view any unpublished chutier entities'
- 'view any unpublished fil entities'
- 'view assigned domains'
- 'view autre_son revisions'
- 'view domain aliases'
@@ -172,5 +206,9 @@ permissions:
- 'view own unpublished content'
- 'view page revisions'
- 'view profile'
- 'view published chutier entities'
- 'view published fil entities'
- 'view static revisions'
- 'view the administration theme'
- 'view unpublished chutier entities'
- 'view unpublished fil entities'