diff --git a/sites/all/modules/figli/edlp_studio/chutier.page.inc b/sites/all/modules/figli/edlp_studio/chutier.page.inc new file mode 100644 index 000000000..2dda2ad31 --- /dev/null +++ b/sites/all/modules/figli/edlp_studio/chutier.page.inc @@ -0,0 +1,30 @@ +' . t('About') . ''; + $output .= '
' . t('Edlp module that handle chutier and fils entities') . '
'; + return $output; + + default: + } +} diff --git a/sites/all/modules/figli/edlp_studio/edlp_studio.permissions.yml b/sites/all/modules/figli/edlp_studio/edlp_studio.permissions.yml new file mode 100644 index 000000000..93dbdf377 --- /dev/null +++ b/sites/all/modules/figli/edlp_studio/edlp_studio.permissions.yml @@ -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' diff --git a/sites/all/modules/figli/edlp_studio/edlp_studio.routing.yml b/sites/all/modules/figli/edlp_studio/edlp_studio.routing.yml new file mode 100644 index 000000000..5ec1eae7c --- /dev/null +++ b/sites/all/modules/figli/edlp_studio/edlp_studio.routing.yml @@ -0,0 +1,7 @@ +edlp_studio.studio: + path: '/admin/structure/studio' + defaults: + _controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage' + _title: 'Studio' + requirements: + _permission: 'administer studio' diff --git a/sites/all/modules/figli/edlp_studio/fil.page.inc b/sites/all/modules/figli/edlp_studio/fil.page.inc new file mode 100644 index 000000000..2c134e62a --- /dev/null +++ b/sites/all/modules/figli/edlp_studio/fil.page.inc @@ -0,0 +1,30 @@ +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'); + } + +} diff --git a/sites/all/modules/figli/edlp_studio/src/ChutierHtmlRouteProvider.php b/sites/all/modules/figli/edlp_studio/src/ChutierHtmlRouteProvider.php new file mode 100644 index 000000000..398ddf3f5 --- /dev/null +++ b/sites/all/modules/figli/edlp_studio/src/ChutierHtmlRouteProvider.php @@ -0,0 +1,56 @@ +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; + } + } + +} diff --git a/sites/all/modules/figli/edlp_studio/src/ChutierListBuilder.php b/sites/all/modules/figli/edlp_studio/src/ChutierListBuilder.php new file mode 100644 index 000000000..c1082379e --- /dev/null +++ b/sites/all/modules/figli/edlp_studio/src/ChutierListBuilder.php @@ -0,0 +1,40 @@ +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); + } + +} diff --git a/sites/all/modules/figli/edlp_studio/src/Entity/Chutier.php b/sites/all/modules/figli/edlp_studio/src/Entity/Chutier.php new file mode 100644 index 000000000..828f7fb70 --- /dev/null +++ b/sites/all/modules/figli/edlp_studio/src/Entity/Chutier.php @@ -0,0 +1,242 @@ + \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; + } + +} diff --git a/sites/all/modules/figli/edlp_studio/src/Entity/ChutierInterface.php b/sites/all/modules/figli/edlp_studio/src/Entity/ChutierInterface.php new file mode 100644 index 000000000..d67dbac92 --- /dev/null +++ b/sites/all/modules/figli/edlp_studio/src/Entity/ChutierInterface.php @@ -0,0 +1,77 @@ + \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; + } + +} diff --git a/sites/all/modules/figli/edlp_studio/src/Entity/FilInterface.php b/sites/all/modules/figli/edlp_studio/src/Entity/FilInterface.php new file mode 100644 index 000000000..922f9f9c1 --- /dev/null +++ b/sites/all/modules/figli/edlp_studio/src/Entity/FilInterface.php @@ -0,0 +1,77 @@ +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'); + } + +} diff --git a/sites/all/modules/figli/edlp_studio/src/FilHtmlRouteProvider.php b/sites/all/modules/figli/edlp_studio/src/FilHtmlRouteProvider.php new file mode 100644 index 000000000..9084e8edd --- /dev/null +++ b/sites/all/modules/figli/edlp_studio/src/FilHtmlRouteProvider.php @@ -0,0 +1,56 @@ +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; + } + } + +} diff --git a/sites/all/modules/figli/edlp_studio/src/FilListBuilder.php b/sites/all/modules/figli/edlp_studio/src/FilListBuilder.php new file mode 100644 index 000000000..1c084046c --- /dev/null +++ b/sites/all/modules/figli/edlp_studio/src/FilListBuilder.php @@ -0,0 +1,40 @@ +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); + } + +} diff --git a/sites/all/modules/figli/edlp_studio/src/Form/ChutierDeleteForm.php b/sites/all/modules/figli/edlp_studio/src/Form/ChutierDeleteForm.php new file mode 100644 index 000000000..33f9a1229 --- /dev/null +++ b/sites/all/modules/figli/edlp_studio/src/Form/ChutierDeleteForm.php @@ -0,0 +1,15 @@ +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()]); + } + +} diff --git a/sites/all/modules/figli/edlp_studio/src/Form/ChutierSettingsForm.php b/sites/all/modules/figli/edlp_studio/src/Form/ChutierSettingsForm.php new file mode 100644 index 000000000..d28d58737 --- /dev/null +++ b/sites/all/modules/figli/edlp_studio/src/Form/ChutierSettingsForm.php @@ -0,0 +1,53 @@ +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()]); + } + +} diff --git a/sites/all/modules/figli/edlp_studio/src/Form/FilSettingsForm.php b/sites/all/modules/figli/edlp_studio/src/Form/FilSettingsForm.php new file mode 100644 index 000000000..f5f4336f3 --- /dev/null +++ b/sites/all/modules/figli/edlp_studio/src/Form/FilSettingsForm.php @@ -0,0 +1,53 @@ + + {% if content %} + {{- content -}} + {% endif %} + diff --git a/sites/all/modules/figli/edlp_studio/templates/fil.html.twig b/sites/all/modules/figli/edlp_studio/templates/fil.html.twig new file mode 100644 index 000000000..fef7ae57f --- /dev/null +++ b/sites/all/modules/figli/edlp_studio/templates/fil.html.twig @@ -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 + */ +#} +