Commit e780ea21 authored by Νίκος Κατσαούνος's avatar Νίκος Κατσαούνος
Browse files

added Sectors entity, updated Course entity, added Sectors form, added...

added Sectors entity, updated Course entity, added Sectors form, added SectorCourses form, added ApplicationPreview form
parent 7ee3620d
<?php
/**
* @file
* Contains eepal_sectors.page.inc.
*
* Page callback for Eepal sectors entities.
*/
use Drupal\Core\Render\Element;
/**
* Prepares variables for Eepal sectors templates.
*
* Default template: eepal_sectors.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_eepal_sectors(array &$variables) {
// Fetch EepalSectors Entity Object.
$eepal_sectors = $variables['elements']['#eepal_sectors'];
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
......@@ -28,3 +28,8 @@ entity.eepal_specialties_in_epal.add_form:
title: 'Add Eepal specialties in epal'
appears_on:
- entity.eepal_specialties_in_epal.collection
entity.eepal_sectors.add_form:
route_name: entity.eepal_sectors.add_form
title: 'Add Eepal sectors'
appears_on:
- entity.eepal_sectors.collection
......@@ -82,3 +82,17 @@ eepal_specialties_in_epal.admin.structure.settings:
description: 'Configure Eepal specialties in epal entities'
route_name: eepal_specialties_in_epal.settings
parent: system.admin_structure
# Eepal sectors menu items definition
entity.eepal_sectors.collection:
title: 'Eepal sectors list'
route_name: entity.eepal_sectors.collection
description: 'List Eepal sectors entities'
parent: system.admin_structure
weight: 100
eepal_sectors.admin.structure.settings:
title: Eepal sectors settings
description: 'Configure Eepal sectors entities'
route_name: eepal_sectors.settings
parent: system.admin_structure
......@@ -130,3 +130,25 @@ entity.eepal_specialties_in_epal.delete_form:
title: Delete
weight: 10
# Eepal sectors routing definition
eepal_sectors.settings_tab:
route_name: eepal_sectors.settings
title: 'Settings'
base_route: eepal_sectors.settings
entity.eepal_sectors.canonical:
route_name: entity.eepal_sectors.canonical
base_route: entity.eepal_sectors.canonical
title: 'View'
entity.eepal_sectors.edit_form:
route_name: entity.eepal_sectors.edit_form
base_route: entity.eepal_sectors.canonical
title: 'Edit'
entity.eepal_sectors.delete_form:
route_name: entity.eepal_sectors.delete_form
base_route: entity.eepal_sectors.canonical
title: Delete
weight: 10
......@@ -130,3 +130,25 @@ view published eepal specialties in epal entities:
view unpublished eepal specialties in epal entities:
title: 'View unpublished Eepal specialties in epal entities'
add eepal sectors entities:
title: 'Create new Eepal sectors entities'
administer eepal sectors entities:
title: 'Administer Eepal sectors entities'
description: 'Allow to access the administration form to configure Eepal sectors entities.'
restrict access: true
delete eepal sectors entities:
title: 'Delete Eepal sectors entities'
edit eepal sectors entities:
title: 'Edit Eepal sectors entities'
access eepal sectors overview:
title: 'Access the Eepal sectors overview page'
view published eepal sectors entities:
title: 'View published Eepal sectors entities'
view unpublished eepal sectors entities:
title: 'View unpublished Eepal sectors entities'
<?php
namespace Drupal\epalreadydata;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
/**
* Access controller for the Eepal sectors entity.
*
* @see \Drupal\epalreadydata\Entity\EepalSectors.
*/
class EepalSectorsAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\epalreadydata\Entity\EepalSectorsInterface $entity */
switch ($operation) {
case 'view':
if (!$entity->isPublished()) {
return AccessResult::allowedIfHasPermission($account, 'view unpublished eepal sectors entities');
}
return AccessResult::allowedIfHasPermission($account, 'view published eepal sectors entities');
case 'update':
return AccessResult::allowedIfHasPermission($account, 'edit eepal sectors entities');
case 'delete':
return AccessResult::allowedIfHasPermission($account, 'delete eepal sectors entities');
}
// Unknown operation, no opinion.
return AccessResult::neutral();
}
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'add eepal sectors entities');
}
}
<?php
namespace Drupal\epalreadydata;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
/**
* Provides routes for Eepal sectors entities.
*
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
*/
class EepalSectorsHtmlRouteProvider extends AdminHtmlRouteProvider {
/**
* {@inheritdoc}
*/
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);
$entity_type_id = $entity_type->id();
if ($collection_route = $this->getCollectionRoute($entity_type)) {
$collection->add("entity.{$entity_type_id}.collection", $collection_route);
}
if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
$collection->add("$entity_type_id.settings", $settings_form_route);
}
return $collection;
}
/**
* Gets the collection route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getCollectionRoute(EntityTypeInterface $entity_type) {
if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass()) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('collection'));
$route
->setDefaults([
'_entity_list' => $entity_type_id,
'_title' => "{$entity_type->getLabel()} list",
])
->setRequirement('_permission', 'access eepal sectors overview')
->setOption('_admin_route', TRUE);
return $route;
}
}
/**
* Gets the settings form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
if (!$entity_type->getBundleEntityType()) {
$route = new Route("/admin/structure/{$entity_type->id()}/settings");
$route
->setDefaults([
'_form' => 'Drupal\epalreadydata\Form\EepalSectorsSettingsForm',
'_title' => "{$entity_type->getLabel()} settings",
])
->setRequirement('_permission', $entity_type->getAdminPermission())
->setOption('_admin_route', TRUE);
return $route;
}
}
}
<?php
namespace Drupal\epalreadydata;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Routing\LinkGeneratorTrait;
use Drupal\Core\Url;
/**
* Defines a class to build a listing of Eepal sectors entities.
*
* @ingroup epalreadydata
*/
class EepalSectorsListBuilder extends EntityListBuilder {
use LinkGeneratorTrait;
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['id'] = $this->t('Eepal sectors ID');
$header['name'] = $this->t('Name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\epalreadydata\Entity\EepalSectors */
$row['id'] = $entity->id();
$row['name'] = $this->l(
$entity->label(),
new Url(
'entity.eepal_sectors.edit_form', array(
'eepal_sectors' => $entity->id(),
)
)
);
return $row + parent::buildRow($entity);
}
}
<?php
namespace Drupal\epalreadydata;
use Drupal\content_translation\ContentTranslationHandler;
/**
* Defines the translation handler for eepal_sectors.
*/
class EepalSectorsTranslationHandler extends ContentTranslationHandler {
// Override here the needed methods from ContentTranslationHandler.
}
<?php
namespace Drupal\epalreadydata\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 Eepal sectors entity.
*
* @ingroup epalreadydata
*
* @ContentEntityType(
* id = "eepal_sectors",
* label = @Translation("Eepal sectors"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\epalreadydata\EepalSectorsListBuilder",
* "views_data" = "Drupal\epalreadydata\Entity\EepalSectorsViewsData",
* "translation" = "Drupal\epalreadydata\EepalSectorsTranslationHandler",
*
* "form" = {
* "default" = "Drupal\epalreadydata\Form\EepalSectorsForm",
* "add" = "Drupal\epalreadydata\Form\EepalSectorsForm",
* "edit" = "Drupal\epalreadydata\Form\EepalSectorsForm",
* "delete" = "Drupal\epalreadydata\Form\EepalSectorsDeleteForm",
* },
* "access" = "Drupal\epalreadydata\EepalSectorsAccessControlHandler",
* "route_provider" = {
* "html" = "Drupal\epalreadydata\EepalSectorsHtmlRouteProvider",
* },
* },
* base_table = "eepal_sectors",
* data_table = "eepal_sectors_field_data",
* translatable = TRUE,
* admin_permission = "administer eepal sectors entities",
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* "uid" = "user_id",
* "langcode" = "langcode",
* "status" = "status",
* },
* links = {
* "canonical" = "/admin/structure/eepal_sectors/{eepal_sectors}",
* "add-form" = "/admin/structure/eepal_sectors/add",
* "edit-form" = "/admin/structure/eepal_sectors/{eepal_sectors}/edit",
* "delete-form" = "/admin/structure/eepal_sectors/{eepal_sectors}/delete",
* "collection" = "/admin/structure/eepal_sectors",
* },
* field_ui_base_route = "eepal_sectors.settings"
* )
*/
class EepalSectors extends ContentEntityBase implements EepalSectorsInterface {
use EntityChangedTrait;
/**
* {@inheritdoc}
*/
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
$values += array(
'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 Eepal sectors entity.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setTranslatable(TRUE)
->setDisplayOptions('view', array(
'label' => 'hidden',
'type' => 'author',
'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);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the Eepal sectors entity.'))
->setSettings(array(
'max_length' => 100,
'text_processing' => 0,
))
->setDefaultValue('')
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
'weight' => -4,
))
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => -4,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Publishing status'))
->setDescription(t('A boolean indicating whether the Eepal sectors is published.'))
->setDefaultValue(TRUE);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the entity was last edited.'));
return $fields;
}
}
<?php
namespace Drupal\epalreadydata\Entity;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\user\EntityOwnerInterface;
/**
* Provides an interface for defining Eepal sectors entities.
*
* @ingroup epalreadydata
*/
interface EepalSectorsInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface {
// Add get/set methods for your configuration properties here.
/**
* Gets the Eepal sectors name.
*
* @return string
* Name of the Eepal sectors.
*/
public function getName();
/**
* Sets the Eepal sectors name.
*
* @param string $name
* The Eepal sectors name.
*
* @return \Drupal\epalreadydata\Entity\EepalSectorsInterface
* The called Eepal sectors entity.
*/
public function setName($name);
/**
* Gets the Eepal sectors creation timestamp.
*
* @return int
* Creation timestamp of the Eepal sectors.
*/
public function getCreatedTime();
/**
* Sets the Eepal sectors creation timestamp.
*
* @param int $timestamp
* The Eepal sectors creation timestamp.
*
* @return \Drupal\epalreadydata\Entity\EepalSectorsInterface
* The called Eepal sectors entity.
*/
public function setCreatedTime($timestamp);
/**
* Returns the Eepal sectors published status indicator.
*
* Unpublished Eepal sectors are only visible to restricted users.
*
* @return bool
* TRUE if the Eepal sectors is published.
*/
public function isPublished();
/**
* Sets the published status of a Eepal sectors.
*
* @param bool $published