eepal initial commit

parents
{
"name": "drupal/eepal",
"type": "drupal-module",
"description": "EPAL Students Registration System",
"keywords": ["Drupal"],
"license": "GPL-2.0+",
"homepage": "https://www.drupal.org/project/eepal",
"minimum-stability": "dev",
"support": {
"issues": "https://www.drupal.org/project/issues/eepal",
"source": "http://cgit.drupalcode.org/eepal"
},
"require": { }
}
.odd {
color: red;
}
name: eepal
type: module
description: EPAL Students Registration System
core: 8.x
package: eEPAL System
<?php
/**
* @file
* Contains eepal.install..
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Implements hook_update_N().
*/
function eepal_update_8201() {
\Drupal::entityDefinitionUpdateManager()->applyUpdates();
}
function node_update_8202() {
// Install the definition that this field had in
// \Drupal\eepal\Entity\StudentClass::baseFieldDefinitions()
// at the time that this update function was written. If/when code is
// deployed that changes that definition, the corresponding module must
// implement an update function that invokes
// \Drupal::entityDefinitionUpdateManager()->updateFieldStorageDefinition()
// with the new definition.
$storage_definition = BaseFieldDefinition::create('boolean')
->setLabel(t('Is Sector Class'))
->setDescription(t('Indicates if this is a sector class.'))
->setReadOnly(TRUE)
->setRevisionable(TRUE)
->setTranslatable(TRUE);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('issectorclass', 'student_class', 'student_class', $storage_definition);
}
/**
* Implements hook_update_N().
*/
function eepal_update_8203() {
\Drupal::entityDefinitionUpdateManager()->applyUpdates();
}
/**
* Implements hook_update_N().
*/
function eepal_update_8204() {
\Drupal::entityDefinitionUpdateManager()->applyUpdates();
}
/**
* Implements hook_update_N().
*/
function eepal_update_8205() {
\Drupal::entityDefinitionUpdateManager()->applyUpdates();
}
eepal-styles:
version: 8.2.3
css:
base:
css/eepal.css: {}
data-tables:
css:
theme:
https://cdn.datatables.net/t/bs/jszip-2.5.0,pdfmake-0.1.18,dt-1.10.11,b-1.1.2,b-colvis-1.1.2,b-flash-1.1.2,b-html5-1.1.2,b-print-1.1.2,cr-1.3.1,fc-3.2.1,fh-3.1.1,kt-2.1.1,r-2.0.2,rr-1.1.1,sc-1.4.1,se-1.1.2/datatables.min.css: { type: external, minified: true }
js:
https://cdn.datatables.net/t/bs/jszip-2.5.0,pdfmake-0.1.18,dt-1.10.11,b-1.1.2,b-colvis-1.1.2,b-flash-1.1.2,b-html5-1.1.2,b-print-1.1.2,cr-1.3.1,fc-3.2.1,fh-3.1.1,kt-2.1.1,r-2.0.2,rr-1.1.1,sc-1.4.1,se-1.1.2/datatables.min.js: { type: external, minified: true }
js/datatables-config.js: {}
dependencies:
- core/jquery
entity.student_class.add_form:
route_name: entity.student_class.add_form
title: 'Add Student class'
appears_on:
- entity.student_class.collection
entity.student.add_form:
route_name: entity.student.add_form
title: 'Add Student'
appears_on:
- entity.student.collection
# Student class menu items definition
entity.student_class.collection:
title: 'Student class list'
route_name: entity.student_class.collection
description: 'List Student class entities'
parent: system.admin_structure
weight: 100
student_class.admin.structure.settings:
title: Student class settings
description: 'Configure Student class entities'
route_name: student_class.settings
parent: system.admin_structure
# Student menu items definition
entity.student.collection:
title: 'Student list'
route_name: entity.student.collection
description: 'List Student entities'
parent: system.admin_structure
weight: 100
student.admin.structure.settings:
title: Student settings
description: 'Configure Student entities'
route_name: student.settings
parent: system.admin_structure
# Student class routing definition
student_class.settings_tab:
route_name: student_class.settings
title: 'Settings'
base_route: student_class.settings
entity.student_class.canonical:
route_name: entity.student_class.canonical
base_route: entity.student_class.canonical
title: 'View'
entity.student_class.edit_form:
route_name: entity.student_class.edit_form
base_route: entity.student_class.canonical
title: 'Edit'
entity.student_class.version_history:
route_name: entity.student_class.version_history
base_route: entity.student_class.canonical
title: 'Revisions'
entity.student_class.delete_form:
route_name: entity.student_class.delete_form
base_route: entity.student_class.canonical
title: Delete
weight: 10
# Student routing definition
student.settings_tab:
route_name: student.settings
title: 'Settings'
base_route: student.settings
entity.student.canonical:
route_name: entity.student.canonical
base_route: entity.student.canonical
title: 'View'
entity.student.edit_form:
route_name: entity.student.edit_form
base_route: entity.student.canonical
title: 'Edit'
entity.student.version_history:
route_name: entity.student.version_history
base_route: entity.student.canonical
title: 'Revisions'
entity.student.delete_form:
route_name: entity.student.delete_form
base_route: entity.student.canonical
title: Delete
weight: 10
<?php
/**
* @file
* Contains eepal.module..
*/
use Drupal\Core\Routing\RouteMatchInterface;
use \Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Implements hook_help().
*/
function eepal_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the eepal module.
case 'help.page.eepal':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('EPAL Students Registration System') . '</p>';
return $output;
default:
}
}
function eepal_form_user_register_form_alter(&$form, FormStateInterface $form_state) {
// Code to alter form or form state here / add a field
$form['amka'] = array(
'#required' => TRUE,
'#type' => 'textfield',
'#title' => t('ΑΜΚΑ'),
);
//validate via callback function eepal_validate
array_unshift($form['#validate'], 'eepal_user_register_form_validate');
// $form['#validate'][] = 'first_module_valid';
//submit via callback function eepal_user_register_form_submit_handler
$form['actions']['submit']['#submit'][] = 'eepal_user_register_form_submit_handler';
}
function eepal_user_register_form_validate(array&$form, FormStateInterface $form_state) {
if (!$form_state->isValueEmpty('amka') && !is_numeric($form_state->getValue('amka'))) {
$form_state->setErrorByName('amka', t('Your amka should be number'));
}
}
function eepal_user_register_form_submit_handler(array&$form, FormStateInterface $form_state) {
//code to insert amka in a table schema
}
function eepal_form_user_login_form_alter(&$form, FormStateInterface $form_state) {
$form['actions']['submit']['#submit'][] = 'eepal_user_login_form_submit_handler';
}
function eepal_user_login_form_submit_handler(array&$form, FormStateInterface $form_state) {
$form_state->setRedirect('eepal_processall');
}
add student class entities:
title: 'Create new Student class entities'
administer student class entities:
title: 'Administer Student class entities'
description: 'Allow to access the administration form to configure Student class entities.'
restrict access: true
delete student class entities:
title: 'Delete Student class entities'
edit student class entities:
title: 'Edit Student class entities'
access student class overview:
title: 'Access the Student class overview page'
view published student class entities:
title: 'View published Student class entities'
view unpublished student class entities:
title: 'View unpublished Student class entities'
view all student class revisions:
title: 'View all Student class revisions'
revert all student class revisions:
title: 'Revert all Student class revisions'
description: 'Role requires permission <em>view Student class revisions</em> and <em>edit rights</em> for student class entities in question or <em>administer student class entities</em>.'
delete all student class revisions:
title: 'Delete all revisions'
description: 'Role requires permission to <em>view Student class revisions</em> and <em>delete rights</em> for student class entities in question or <em>administer student class entities</em>.'
add student entities:
title: 'Create new Student entities'
administer student entities:
title: 'Administer Student entities'
description: 'Allow to access the administration form to configure Student entities.'
restrict access: true
delete student entities:
title: 'Delete Student entities'
edit student entities:
title: 'Edit Student entities'
access student overview:
title: 'Access the Student overview page'
view published student entities:
title: 'View published Student entities'
view unpublished student entities:
title: 'View unpublished Student entities'
view all student revisions:
title: 'View all Student revisions'
revert all student revisions:
title: 'Revert all Student revisions'
description: 'Role requires permission <em>view Student revisions</em> and <em>edit rights</em> for student entities in question or <em>administer student entities</em>.'
delete all student revisions:
title: 'Delete all revisions'
description: 'Role requires permission to <em>view Student revisions</em> and <em>delete rights</em> for student entities in question or <em>administer student entities</em>.'
eepal_processall:
path: '/eepal/classes/processall'
defaults:
_controller: '\Drupal\eepal\Controller\ProcessAllController::basicQuery'
requirements:
_access: 'TRUE'
eepal_loadall:
path: '/eepal/classes/loadall'
defaults:
_controller: '\Drupal\eepal\Controller\LoadAllController::loadAll'
requirements:
_access: 'TRUE'
$(function(){
$("#studentclasses").dataTable();
})
<?php
/**
* @file
* Contains \Drupal\query_example\Controller\QueryExampleController.
*/
namespace Drupal\eepal\Controller;
use Drupal\Core\Entity\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Controller\ControllerBase;
/**
* Controller routines for page example routes.
*/
class LoadAllController extends ControllerBase {
protected $entityManager;
/**
* {@inheritdoc}
*/
public function __construct(EntityManagerInterface $entityManager) {
$this->entityManager = $entityManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager')
);
}
/**
* Return a list of nodes that are published.
*/
public function loadAll() {
// We get the node storage object.
$node_storage = $this->entityManager->getStorage('student_class');
// We use the load function to load a single node object.
$nid = 1;
$node = $node_storage->load($nid);
// We load a revision
$revision_id = 1;
$node = $node_storage->loadRevision($revision_id);
// We use the loadMultiple function to load an array of node objects keyed by node ID.
$nids = [1,2];
$nodes = $node_storage->loadMultiple($nids);
// We will discuss this in future lessons, but you can get the value of simple fields using ->get('field_name')->value.
return [
'#markup' => $node->get('name')->value,
];
}
}
<?php
/**
* @file
* Contains \Drupal\query_example\Controller\QueryExampleController.
*/
namespace Drupal\eepal\Controller;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Controller\ControllerBase;
/**
* Controller routines for page example routes.
*/
class ProcessAllController extends ControllerBase {
protected $query_factory;
public function __construct(EntityTypeManagerInterface $entityTypeManager, QueryFactory $query_factory) {
// public function __construct(QueryFactory $query_factory) {
$this->entityTypeManager = $entityTypeManager;
$this->query_factory = $query_factory;
}
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('entity.query')
);
}
protected function simpleQuery() {
$query = $this->query_factory->get('student_class');
// ->condition('status', 1);
$scids = $query->execute();
$studentClass_storage = $this->entityTypeManager->getStorage('student_class');
$studentClasses = $studentClass_storage->loadMultiple($scids);
$arrayToReturn = array();
foreach ($studentClasses as $studentClass) {
array_push($arrayToReturn, array($studentClass->get('name')->value, $studentClass->get('maxno')->value));
}
return array_values($arrayToReturn);
}
public function basicQuery() {
return [
'#title' => 'All student class ids',
'studentclasses' => array(
'#attributes' => ['id' => 'studentclasses', 'name' => 'studentclasses'],
'#theme' => 'table',
'#caption' => t('Student Classes'),
'#header' => array(t('Name'), t('Max No')),
'#rows' => $this->simpleQuery(),
),
'#attached' => [
'library' => [
'eepal/eepal-styles', //include our custom module library for this response
'eepal/data-tables' //include data tables libraries with this response
]
]
];
}
protected function intermediateQuery() {
$query = $this->query_factory->get('node')
->condition('status', 1)
->condition('changed', REQUEST_TIME, '<')
->condition('title', 'ipsum lorem', 'CONTAINS')
->condition('field_tags.entity.name', 'test');
$nids = $query->execute();
return array_values($nids);
}
public function conditionalQuery() {
return [
'#title' => 'Published Nodes Called "ipsum lorem" That Have a Tag "test"',
'content' => [
'#theme' => 'item_list',
'#items' => $this->intermediateQuery()
]
];
}
protected function advancedQuery() {
$query = $this->query_factory->get('node')
->condition('status', 1)
->condition('changed', REQUEST_TIME, '<');
$group = $query->orConditionGroup()
->condition('title', 'ipsum lorem', 'CONTAINS')
->condition('field_tags.entity.name', 'test');
$nids = $query->condition($group)->execute();
return array_values($nids);
}
public function conditionalGroupQuery() {
return [
'#title' => 'Published Nodes That Are Called "ipsum lorem" Or Have a Tag "test"',
'content' => [
'#theme' => 'item_list',
'#items' => $this->advancedQuery()
]
];
}
}
<?php
namespace Drupal\eepal\Controller;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Url;
use Drupal\eepal\Entity\StudentClassInterface;
/**
* Class StudentClassController.
*
* Returns responses for Student class routes.
*
* @package Drupal\eepal\Controller
*/
class StudentClassController extends ControllerBase implements ContainerInjectionInterface {
/**
* Displays a Student class revision.
*
* @param int $student_class_revision
* The Student class revision ID.
*
* @return array
* An array suitable for drupal_render().
*/
public function revisionShow($student_class_revision) {
$student_class = $this->entityManager()->getStorage('student_class')->loadRevision($student_class_revision);
$view_builder = $this->entityManager()->getViewBuilder('student_class');
return $view_builder->view($student_class);
}
/**
* Page title callback for a Student class revision.
*
* @param int $student_class_revision
* The Student class revision ID.
*
* @return string
* The page title.
*/
public function revisionPageTitle($student_class_revision) {
$student_class = $this->entityManager()->getStorage('student_class')->loadRevision($student_class_revision);
return $this->t('Revision of %title from %date', array('%title' => $student_class->label(), '%date' => format_date($student_class->getRevisionCreationTime())));
}
/**
* Generates an overview table of older revisions of a Student class .
*
* @param \Drupal\eepal\Entity\StudentClassInterface $student_class
* A Student class object.
*
* @return array
* An array as expected by drupal_render().
*/
public function revisionOverview(StudentClassInterface $student_class) {
$account = $this->currentUser();
$langcode = $student_class->language()->getId();
$langname = $student_class->language()->getName();
$languages = $student_class->getTranslationLanguages();
$has_translations = (count($languages) > 1);
$student_class_storage = $this->entityManager()->getStorage('student_class');
$build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => $student_class->label()]) : $this->t('Revisions for %title', ['%title' => $student_class->label()]);
$header = array($this->t('Revision'), $this->t('Operations'));
$revert_permission = (($account->hasPermission("revert all student class revisions") || $account->hasPermission('administer student class entities')));
$delete_permission = (($account->hasPermission("delete all student class revisions") || $account->hasPermission('administer student class entities')));
$rows = array();
$vids = $student_class_storage->revisionIds($student_class);
$latest_revision = TRUE;
foreach (array_reverse($vids) as $vid) {
/** @var \Drupal\eepal\StudentClassInterface $revision */
$revision = $student_class_storage->loadRevision($vid);
// Only show revisions that are affected by the language that is being
// displayed.
if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) {
$username = [
'#theme' => 'username',
'#account' => $revision->getRevisionAuthor(),
];
// Use revision link to link to revisions that are not active.
$date = \Drupal::service('date.formatter')->format($revision->revision_timestamp->value, 'short');
if ($vid != $student_class->getRevisionId()) {
$link = $this->l($date, new Url('entity.student_class.revision', ['student_class' => $student_class->id(), 'student_class_revision' => $vid]));
}
else {
$link = $student_class->link($date);
}
$row = [];
$column = [
'data' => [
'#type' => 'inline_template',
'#template' => '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}',
'#context' => [
'date' => $link,
'username' => \Drupal::service('renderer')->renderPlain($username),
'message' => ['#markup' => $revision->revision_log_message->value, '#allowed_tags' => Xss::getHtmlTagList()],
],
],
];
$row[] = $column;
if ($latest_revision) {
$row[] = [
'data' => [
'#prefix' => '<em>',
'#markup' => $this->t('Current revision'),
'#suffix' => '</em>',
],
];
foreach ($row as &$current) {
$current['class'] = ['revision-current'];
}
$latest_revision = FALSE;
}
else {
$links = [];
if ($revert_permission) {
$links['revert'] = [
'title' => $this->t('Revert'),
'url' => $has_translations ?
Url::fromRoute('student_class.revision_revert_translation_confirm', ['student_class' => $student_class->id(), 'student_class_revision' => $vid, 'langcode' => $langcode]) :
Url::fromRoute('student_class.revision_revert_confirm', ['student_class' => $student_class->id(), 'student_class_revision' => $vid]),
];
}
if ($delete_permission) {
$links['delete'] = [
'title' => $this->t('Delete'),
'url' => Url::fromRoute('student_class.revision_delete_confirm', ['student_class' => $student_class->id(), 'student_class_revision' => $vid]),
];
}
$row[] = [
'data' => [
'#type' => 'operations',
'#links' => $links,
],
];
}
$rows[] = $row;
}
}
$build['student_class_revisions_table'] = array(
'#theme' => 'table',
'#rows' => $rows,
'#header' => $header,
);
return $build;
}
}
<?php
namespace Drupal\eepal\Controller;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Url;
use Drupal\eepal\Entity\StudentInterface;
/**
* Class StudentController.
*
* Returns responses for Student routes.
*
* @package Drupal\eepal\Controller
*/
class StudentController extends ControllerBase implements ContainerInjectionInterface {
/**
* Displays a Student revision.
*
* @param int $student_revision
* The Student revision ID.
*
* @return array
* An array suitable for drupal_render().
*/
public function revisionShow($student_revision) {
$student = $this->entityManager()->getStorage('student')->loadRevision($student_revision);
$view_builder = $this->entityManager()->getViewBuilder('student');
return $view_builder->view($student);
}