refactored : entity fil -> entity composition
started to display add to chutier link to contents
This commit is contained in:
+12
-12
@@ -8,40 +8,40 @@ use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
|
||||
/**
|
||||
* Access controller for the Fil entity.
|
||||
* Access controller for the Composition entity.
|
||||
*
|
||||
* @see \Drupal\edlp_studio\Entity\Fil.
|
||||
* @see \Drupal\edlp_studio\Entity\Composition.
|
||||
*/
|
||||
class FilAccessControlHandler extends EntityAccessControlHandler {
|
||||
class CompositionAccessControlHandler extends EntityAccessControlHandler {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
/** @var \Drupal\edlp_studio\Entity\FilInterface $entity */
|
||||
/** @var \Drupal\edlp_studio\Entity\CompositionInterface $entity */
|
||||
switch ($operation) {
|
||||
case 'view':
|
||||
if (!$entity->isPublished()) {
|
||||
if($account->hasPermission('view own unpublished fil entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
|
||||
if($account->hasPermission('view own unpublished composition 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 any unpublished composition entities');
|
||||
}
|
||||
}
|
||||
return AccessResult::allowedIfHasPermission($account, 'view published fil entities');
|
||||
return AccessResult::allowedIfHasPermission($account, 'view published composition entities');
|
||||
|
||||
case 'update':
|
||||
if($account->hasPermission('edit own fil entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
|
||||
if($account->hasPermission('edit own composition entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
|
||||
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
|
||||
}else{
|
||||
return AccessResult::allowedIfHasPermission($account, 'edit any fil entities');
|
||||
return AccessResult::allowedIfHasPermission($account, 'edit any composition entities');
|
||||
}
|
||||
|
||||
case 'delete':
|
||||
if($account->hasPermission('delete own fil entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
|
||||
if($account->hasPermission('delete own composition entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
|
||||
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
|
||||
}else{
|
||||
return AccessResult::allowedIfHasPermission($account, 'delete fil entities');
|
||||
return AccessResult::allowedIfHasPermission($account, 'delete composition entities');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class FilAccessControlHandler extends EntityAccessControlHandler {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'add fil entities');
|
||||
return AccessResult::allowedIfHasPermission($account, 'add composition entities');
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -7,12 +7,12 @@ use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Provides routes for Fil entities.
|
||||
* Provides routes for Composition entities.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class FilHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
class CompositionHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -43,7 +43,7 @@ class FilHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
$route = new Route("/admin/structure/studio/{$entity_type->id()}/settings");
|
||||
$route
|
||||
->setDefaults([
|
||||
'_form' => 'Drupal\edlp_studio\Form\FilSettingsForm',
|
||||
'_form' => 'Drupal\edlp_studio\Form\CompositionSettingsForm',
|
||||
'_title' => "{$entity_type->getLabel()} settings",
|
||||
])
|
||||
->setRequirement('_permission', $entity_type->getAdminPermission())
|
||||
+6
-6
@@ -7,18 +7,18 @@ use Drupal\Core\Entity\EntityListBuilder;
|
||||
use Drupal\Core\Link;
|
||||
|
||||
/**
|
||||
* Defines a class to build a listing of Fil entities.
|
||||
* Defines a class to build a listing of Composition entities.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*/
|
||||
class FilListBuilder extends EntityListBuilder {
|
||||
class CompositionListBuilder extends EntityListBuilder {
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['id'] = $this->t('Fil ID');
|
||||
$header['id'] = $this->t('Composition ID');
|
||||
$header['name'] = $this->t('Name');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
@@ -27,12 +27,12 @@ class FilListBuilder extends EntityListBuilder {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
/* @var $entity \Drupal\edlp_studio\Entity\Fil */
|
||||
/* @var $entity \Drupal\edlp_studio\Entity\Composition */
|
||||
$row['id'] = $entity->id();
|
||||
$row['name'] = Link::createFromRoute(
|
||||
$entity->label(),
|
||||
'entity.fil.edit_form',
|
||||
['fil' => $entity->id()]
|
||||
'entity.composition.edit_form',
|
||||
['composition' => $entity->id()]
|
||||
);
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
|
||||
/**
|
||||
* Class ChutierController.
|
||||
*/
|
||||
class ChutierController extends ControllerBase {
|
||||
|
||||
/**
|
||||
* Hello.
|
||||
*
|
||||
* @return json
|
||||
* Return Hello string.
|
||||
*/
|
||||
public function AddContent($id) {
|
||||
// TODO: get current user
|
||||
// TODO: check if default chutier exists ? yes use it : no create and use it.
|
||||
// TODO: add $id to documents field
|
||||
// TODO: return status
|
||||
|
||||
$response = new JsonResponse();
|
||||
|
||||
$data = array(
|
||||
'test' => 'Hello chutier',
|
||||
);
|
||||
|
||||
$response->setData($data);
|
||||
|
||||
return $response;
|
||||
// return array(
|
||||
// '#markup'=>'Hello Chutier'
|
||||
// ); }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -216,6 +216,7 @@ class Chutier extends ContentEntityBase implements ChutierInterface {
|
||||
->setDescription(t('Documents from collection.'))
|
||||
->setSetting('target_type', 'node')
|
||||
->setSetting('handler', 'default')
|
||||
// TODO: check node content type by settings @see readme
|
||||
->setSetting('handler_settings',['target_bundles'=>['enregistrement'=>'enregistrement']] )
|
||||
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
|
||||
->setDisplayOptions('view', array(
|
||||
|
||||
+23
-23
@@ -10,31 +10,31 @@ use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Defines the Fil entity.
|
||||
* Defines the Composition entity.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "fil",
|
||||
* label = @Translation("Fil"),
|
||||
* id = "composition",
|
||||
* label = @Translation("Composition"),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\edlp_studio\FilListBuilder",
|
||||
* "views_data" = "Drupal\edlp_studio\Entity\FilViewsData",
|
||||
* "list_builder" = "Drupal\edlp_studio\CompositionListBuilder",
|
||||
* "views_data" = "Drupal\edlp_studio\Entity\CompositionViewsData",
|
||||
*
|
||||
* "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",
|
||||
* "default" = "Drupal\edlp_studio\Form\CompositionForm",
|
||||
* "add" = "Drupal\edlp_studio\Form\CompositionForm",
|
||||
* "edit" = "Drupal\edlp_studio\Form\CompositionForm",
|
||||
* "delete" = "Drupal\edlp_studio\Form\CompositionDeleteForm",
|
||||
* },
|
||||
* "access" = "Drupal\edlp_studio\FilAccessControlHandler",
|
||||
* "access" = "Drupal\edlp_studio\CompositionAccessControlHandler",
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\edlp_studio\FilHtmlRouteProvider",
|
||||
* "html" = "Drupal\edlp_studio\CompositionHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* base_table = "fil",
|
||||
* admin_permission = "administer fil entities",
|
||||
* base_table = "composition",
|
||||
* admin_permission = "administer composition entities",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "name",
|
||||
@@ -44,16 +44,16 @@ use Drupal\user\UserInterface;
|
||||
* "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",
|
||||
* "canonical" = "/admin/structure/studio/composition/{composition}",
|
||||
* "add-form" = "/admin/structure/studio/composition/add",
|
||||
* "edit-form" = "/admin/structure/studio/composition/{composition}/edit",
|
||||
* "delete-form" = "/admin/structure/studio/composition/{composition}/delete",
|
||||
* "collection" = "/admin/structure/studio/composition",
|
||||
* },
|
||||
* field_ui_base_route = "fil.settings"
|
||||
* field_ui_base_route = "composition.settings"
|
||||
* )
|
||||
*/
|
||||
class Fil extends ContentEntityBase implements FilInterface {
|
||||
class Composition extends ContentEntityBase implements CompositionInterface {
|
||||
|
||||
use EntityChangedTrait;
|
||||
|
||||
@@ -150,7 +150,7 @@ class Fil extends ContentEntityBase implements FilInterface {
|
||||
|
||||
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Authored by'))
|
||||
->setDescription(t('The user ID of author of the Fil entity.'))
|
||||
->setDescription(t('The user ID of author of the Composition entity.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setSetting('target_type', 'user')
|
||||
->setSetting('handler', 'default')
|
||||
@@ -175,7 +175,7 @@ class Fil extends ContentEntityBase implements FilInterface {
|
||||
|
||||
$fields['name'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Name'))
|
||||
->setDescription(t('The name of the Fil entity.'))
|
||||
->setDescription(t('The name of the Composition entity.'))
|
||||
->setSettings([
|
||||
'max_length' => 50,
|
||||
'text_processing' => 0,
|
||||
@@ -196,7 +196,7 @@ class Fil extends ContentEntityBase implements FilInterface {
|
||||
|
||||
$fields['status'] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Publishing status'))
|
||||
->setDescription(t('A boolean indicating whether the Fil is published.'))
|
||||
->setDescription(t('A boolean indicating whether the Composition is published.'))
|
||||
->setDefaultValue(TRUE)
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'boolean_checkbox',
|
||||
@@ -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 Composition entities.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*/
|
||||
interface CompositionInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
|
||||
/**
|
||||
* Gets the Composition name.
|
||||
*
|
||||
* @return string
|
||||
* Name of the Composition.
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Sets the Composition name.
|
||||
*
|
||||
* @param string $name
|
||||
* The Composition name.
|
||||
*
|
||||
* @return \Drupal\edlp_studio\Entity\CompositionInterface
|
||||
* The called Composition entity.
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* Gets the Composition creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* Creation timestamp of the Composition.
|
||||
*/
|
||||
public function getCreatedTime();
|
||||
|
||||
/**
|
||||
* Sets the Composition creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The Composition creation timestamp.
|
||||
*
|
||||
* @return \Drupal\edlp_studio\Entity\CompositionInterface
|
||||
* The called Composition entity.
|
||||
*/
|
||||
public function setCreatedTime($timestamp);
|
||||
|
||||
/**
|
||||
* Returns the Composition published status indicator.
|
||||
*
|
||||
* Unpublished Composition are only visible to restricted users.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the Composition is published.
|
||||
*/
|
||||
public function isPublished();
|
||||
|
||||
/**
|
||||
* Sets the published status of a Composition.
|
||||
*
|
||||
* @param bool $published
|
||||
* TRUE to set this Composition to published, FALSE to set it to unpublished.
|
||||
*
|
||||
* @return \Drupal\edlp_studio\Entity\CompositionInterface
|
||||
* The called Composition entity.
|
||||
*/
|
||||
public function setPublished($published);
|
||||
|
||||
}
|
||||
+2
-2
@@ -5,9 +5,9 @@ namespace Drupal\edlp_studio\Entity;
|
||||
use Drupal\views\EntityViewsData;
|
||||
|
||||
/**
|
||||
* Provides Views data for Fil entities.
|
||||
* Provides Views data for Composition entities.
|
||||
*/
|
||||
class FilViewsData extends EntityViewsData {
|
||||
class CompositionViewsData extends EntityViewsData {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -1,77 +0,0 @@
|
||||
<?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);
|
||||
|
||||
}
|
||||
+2
-2
@@ -5,11 +5,11 @@ namespace Drupal\edlp_studio\Form;
|
||||
use Drupal\Core\Entity\ContentEntityDeleteForm;
|
||||
|
||||
/**
|
||||
* Provides a form for deleting Fil entities.
|
||||
* Provides a form for deleting Composition entities.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*/
|
||||
class FilDeleteForm extends ContentEntityDeleteForm {
|
||||
class CompositionDeleteForm extends ContentEntityDeleteForm {
|
||||
|
||||
|
||||
}
|
||||
+6
-6
@@ -6,17 +6,17 @@ use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Form controller for Fil edit forms.
|
||||
* Form controller for Composition edit forms.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*/
|
||||
class FilForm extends ContentEntityForm {
|
||||
class CompositionForm extends ContentEntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
/* @var $entity \Drupal\edlp_studio\Entity\Fil */
|
||||
/* @var $entity \Drupal\edlp_studio\Entity\Composition */
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
$entity = $this->entity;
|
||||
@@ -34,17 +34,17 @@ class FilForm extends ContentEntityForm {
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
drupal_set_message($this->t('Created the %label Fil.', [
|
||||
drupal_set_message($this->t('Created the %label Composition.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Fil.', [
|
||||
drupal_set_message($this->t('Saved the %label Composition.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirect('entity.fil.canonical', ['fil' => $entity->id()]);
|
||||
$form_state->setRedirect('entity.composition.canonical', ['composition' => $entity->id()]);
|
||||
}
|
||||
|
||||
}
|
||||
+5
-5
@@ -6,11 +6,11 @@ use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class FilSettingsForm.
|
||||
* Class CompositionSettingsForm.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*/
|
||||
class FilSettingsForm extends FormBase {
|
||||
class CompositionSettingsForm extends FormBase {
|
||||
|
||||
/**
|
||||
* Returns a unique string identifying the form.
|
||||
@@ -19,7 +19,7 @@ class FilSettingsForm extends FormBase {
|
||||
* The unique string identifying the form.
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'fil_settings';
|
||||
return 'composition_settings';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ class FilSettingsForm extends FormBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the settings form for Fil entities.
|
||||
* Defines the settings form for Composition entities.
|
||||
*
|
||||
* @param array $form
|
||||
* An associative array containing the structure of the form.
|
||||
@@ -46,7 +46,7 @@ class FilSettingsForm extends FormBase {
|
||||
* Form definition array.
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['fil_settings']['#markup'] = 'Settings form for Fil entities. Manage field settings here.';
|
||||
$form['composition_settings']['#markup'] = 'Settings form for Composition entities. Manage field settings here.';
|
||||
return $form;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user