Commit acca5b3a authored by Αχιλλέας Κατσαρός's avatar Αχιλλέας Κατσαρός

Merge branch 'new_feature3' into 'develop'

updates to eiek entitychanger maincustomform and upload new d8views custom module

See merge request !4
parents 8bd7f078 3506ed37
{
"name": "drupal/d8views",
"type": "drupal-module",
"description": "d8 Views Changer",
"keywords": ["Drupal"],
"license": "GPL-2.0+",
"homepage": "https://www.drupal.org/project/d8views",
"minimum-stability": "dev",
"support": {
"issues": "https://www.drupal.org/project/issues/d8views",
"source": "http://cgit.drupalcode.org/d8views"
},
"require": { }
}
name: d8views
type: module
description: d8 Views Changer
core: 8.x
package: Custom
dependencies:
- eiek
- entitychanger
\ No newline at end of file
<?php
/**
* @file
* Contains d8views.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function d8views_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the d8views module.
case 'help.page.d8views':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('d8 Views Changer') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_theme().
*/
function d8views_theme() {
return [
'd8views' => [
'template' => 'd8views',
'render element' => 'children',
],
'edit_iek_form' => [
'render element' => 'form',
],
];
}
d8views.edit_iek_form:
path: '/iek/aitisi/{aid}/edit'
defaults:
_form: '\Drupal\d8views\Form\EditIekForm'
_title: 'EditIekForm'
requirements:
_access: 'TRUE'
<?php
/**
* @file
* Contains d8views\d8views.views.inc..
* Provide a custom views field data that isn't tied to any other module. */
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Render\Markup;
use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\system\ActionConfigEntityInterface;
/**
* Implements hook_views_data_alter().
*/
function d8views_views_data_alter(array &$data) {
$data['aitisi_entity']['node_type_flagger'] = array(
'title' => t('Node type flagger'),
'field' => array(
'title' => t('Node type flagger'),
'help' => t('Flags a specific node type.'),
'id' => 'node_type_flagger',
),
);
$data['aitisi_entity']['baseurlvalue'] = array(
'title' => t('Base URL value'),
'field' => array(
'title' => t('Base URL value'),
'id' => 'baseurlvalue',
),
);
$data['aitisi_entity']['node_type_filter'] = array(
'title' => t('Enhanced node type filter'),
'filter' => array(
'title' => t('Enhanced node type filter'),
'help' => t('Provides a custom filter for nodes by their type.'),
'field' => 'type',
'id' => 'string'
),
);
$data['aitisi_entity']['nodes_titles'] = array(
'title' => t('Node titles'),
'filter' => array(
'title' => t('Node titles'),
'help' => t('Specify a list of titles a node can have.'),
'field' => 'iek_id',
'id' => 'd8views_node_titles'
),
);
}
<?php
function d8views_views_query_alter(Drupal\views\ViewExecutable $view, Drupal\views\Plugin\views\query\Sql $query) {
if ($view->id() == 'test1') {
foreach ($query->where as &$condition_group) {
foreach ($condition_group['conditions'] as &$condition) {
if ($condition['field'] == 'school_entity_aitisi_entity.iekcode') {
$user = \Drupal::service('current_user');
$uid = $user->id();
//$formatted_name = $user->getDisplayName();
$raw_name = $user->getAccountName();
//$raw_name = 'admin';
$condition = array(
'field' => 'school_entity_aitisi_entity.iekcode',
'value' => $raw_name,
'operator' => '=',
);
}
}
}
}
}
\ No newline at end of file
<?php
namespace Drupal\d8views\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Url;
/**
* Class EditIekForm.
*
* @package Drupal\d8views\Form
*/
class EditIekForm extends FormBase {
/**
* Drupal\Core\Entity\EntityManager definition.
*
* @var \Drupal\Core\Entity\EntityManager
*/
protected $entityManager;
protected $entityObject;
public function __construct(
EntityManager $entity_manager
) {
$this->entityManager = $entity_manager;
}
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'edit_iek_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $aid = NULL) {
if(isset($aid)) {
$entity_manager = \Drupal::entityManager();
$entity_storage_aitisi = $entity_manager->getStorage('aitisi_entity');
$aitisiArr = $entity_storage_aitisi->loadByProperties(['id' => $aid]);
$this->entityObject = reset($aitisiArr);
if ($this->entityObject) {
$form['#theme'] = 'edit_iek_form';
$form['numbek'] = [
'#type' => 'textfield',
'#title' => t('Αριθμός ΒΕΚ'),
'#required' => TRUE,
'#default_value' => $this->entityObject->getNumbek() ? $this->entityObject->getNumbek() : '',
'#states' => array(
'disabled' => array(
'input[name="flagiek"]' => array('value' => 1),
),
)
];
$form['prabek'] = [
'#type' => 'textfield',
'#title' => t('Πράξη ΒΕΚ'),
'#required' => TRUE,
'#default_value' => $this->entityObject->getPrabek() ? $this->entityObject->getPrabek() : '',
'#states' => array(
'disabled' => array(
'input[name="flagiek"]' => array('value' => 1),
),
)
];
$form['regno'] = [
'#type' => 'textfield',
'#title' => t('ΑΜΚ'),
'#required' => TRUE,
'#default_value' => $this->entityObject->getRegno() ? $this->entityObject->getRegno() : '',
'#states' => array(
'disabled' => array(
'input[name="flagiek"]' => array('value' => 1),
),
)
];
$form['flagiek'] = array(
'#type' => 'radios',
'#title' => t('Έλεγχος ΙΕΚ'),
'#default_value' => 0,
'#options' => array(0 => t('Αρχική'), 1 => t('Έλεγχος ολοκληρώθηκε')),
'#default_value' => $this->entityObject->getFlagiek() ? $this->entityObject->getFlagiek() : '',
'#states' => array(
'disabled' => array(
'input[name="flagiek"]' => array('value' => 1),
),
)
);
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Submit'),
];
}
// $entity_storage_aitisi->save($entity_object);
}
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Display result.
foreach ($form_state->getValues() as $key => $value) {
drupal_set_message($key . ': ' . $value);
}
$this->entityObject->setNumbek($form_state->getValue('numbek'));
$this->entityObject->setPrabek($form_state->getValue('prabek'));
$this->entityObject->setRegno($form_state->getValue('regno'));
$this->entityObject->setFlagiek($form_state->getValue('flagiek'));
$this->entityObject->save();
$url = Url::fromUserInput('/data/aitiseis/iek');
$form_state->setRedirectUrl($url);
/*
$aitisiArr = $entity_storage_aitisi->loadByProperties(['id' => $aid]);
$aitisiObj = reset($aitisiArr);
if ($aitisiObj) {
$aitisiObj->setNumbek();
$aitisiObj->setPrabek();
$aitisiObj->setRegno();
$aitisiObj->setFlagiek();
$aitisiObj->save();
}
*/
}
}
<?php
namespace Drupal\d8views\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\Random;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
/**
* A handler to provide a field that is completely custom by the administrator.
*
* @ingroup views_field_handlers
*
* @ViewsField("baseurlvalue")
*/
class BaseUrlValue extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function usesGroupBy() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function query() {
// Do nothing -- to override the parent query.
}
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
//$options['hide_alter_empty'] = ['default' => FALSE];
//$options['node_type'] = array('default' => 'article');
return $options;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
// $types = NodeType::loadMultiple();
// $options = [];
/* foreach ($types as $key => $type) {
$options[$key] = $type->label();
}
$form['node_type'] = array(
'#title' => $this->t('Which node type should be flagged?'),
'#type' => 'select',
'#default_value' => $this->options['node_type'],
'#options' => $options,
);*/
parent::buildOptionsForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
// Return a random text, here you can include your custom logic.
// Include any namespace required to call the method required to generate
// the desired output.
//$random = new Random();
//return $random->name();
global $base_url;
return $base_url;
}
}
<?php
namespace Drupal\d8views\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\Random;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
//use Drupal\Core\Form\FormStateInterface;
use Drupal\node\Entity\NodeType;
//use Drupal\views\Plugin\views\field\FieldPluginBase;
//use Drupal\views\ResultRow;
/**
* A handler to provide a field that is completely custom by the administrator.
*
* @ingroup views_field_handlers
*
* @ViewsField("node_type_flagger")
*/
class NodeTypeFlagger extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function usesGroupBy() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function query() {
// Do nothing -- to override the parent query.
}
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
//$options['hide_alter_empty'] = ['default' => FALSE];
$options['node_type'] = array('default' => 'article');
return $options;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$types = NodeType::loadMultiple();
$options = [];
foreach ($types as $key => $type) {
$options[$key] = $type->label();
}
$form['node_type'] = array(
'#title' => $this->t('Which node type should be flagged?'),
'#type' => 'select',
'#default_value' => $this->options['node_type'],
'#options' => $options,
);
parent::buildOptionsForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
// Return a random text, here you can include your custom logic.
// Include any namespace required to call the method required to generate
// the desired output.
//$random = new Random();
//return $random->name();
$node = $values->_entity;
if ($node->bundle() == $this->options['node_type']) {
return $this->t('Hey, I\'m of the type: @type', array('@type' => $this->options['node_type']));
}
else {
return $this->t('Hey, I\'m something else.');
}
}
}
<?php
/**
* @file
* Definition of Drupal\d8views\Plugin\views\filter\NodeTitles.
*/
namespace Drupal\d8views\Plugin\views\filter;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\filter\InOperator;
use Drupal\views\ViewExecutable;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Filters by given list of node title options.
*
* @ingroup views_filter_handlers
*
* @ViewsFilter("d8views_node_titles")
*/
class NodeTitles extends InOperator implements ContainerFactoryPluginInterface {
protected $user;
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountInterface $user) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->user = $user;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('current_user')
);
}
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
//$this->valueTitle = t('Allowed node titles');
// $this->definition['options callback'] = array($this, 'generateOptions');
$uid = $this->user->id();
//$formatted_name = $this->user->getDisplayName();
$raw_name = $this->user->getAccountName();
$this->value = $raw_name;
}
/**
* Override the query so that no filtering takes place if the user doesn't
* select any options.
*/
public function query() {
if (!empty($this->value)) {
parent::query();
}
}
/**
* Skip validation if no options have been chosen so we can use it as a
* non-filter.
*/
public function validate() {
if (!empty($this->value)) {
parent::validate();
}
}
/**
* Helper function that generates the options.
* @return array
*/
public function generateOptions() {
// Array keys are used to compare with the table field values.
$uid = $this->user->id();
//$formatted_name = $this->user->getDisplayName();
$raw_name = $this->user->getAccountName();
return array(
'user name' => $raw_name
);
}
}
\ No newline at end of file
<?php
namespace Drupal\d8views\Tests;
use Drupal\Core\Url;