Commit 1d81fd90 authored by Telenkov Ruslan's avatar Telenkov Ruslan

ALL TASK

parent 7c804b3c
......@@ -37,13 +37,13 @@ class BatchCommands extends DrushCommands
* @param $date Argument with text to be printed
* @aliases go-api
*/
public function goApi($date = null)
{
public function goApi($date = null) {
//дата 0 - не ввели дату
if ($date === null){
$this->output()->writeln('Вы не ввели дату');
return;
}
else {
$timestamp = strtotime($date); //перевод даты в нужный формат
$service = \Drupal::service('myservice.my'); //обраение к сервису
$request = $service->getResult('https://swapi.dev/api/'); // получение адресов апи
......@@ -76,7 +76,6 @@ class BatchCommands extends DrushCommands
} while ($url); // пока есть урл, т е пока у меня есть следующая страница
}
}
}
/**
* A custom Drush command to displays the given text.
*
......
......@@ -6,7 +6,9 @@
function formApi_theme($existing, $type, $theme, $path) {
return [
'form_theme' => [
'variables' => [],
'variables' => [
'result' => '' ,
],
],
];
}
......
......@@ -187,6 +187,23 @@ class FormApiTask extends FormBase {
->execute();
$content1['#attached']['library'][] = 'core/drupal.dialog.ajax';
$myConfigPage = \Drupal\config_pages\Entity\ConfigPages::config('custom_config');
$string_modal = $myConfigPage->get('field_modal_title')->value;
$current_user = \Drupal::currentUser();
$user = \Drupal\user\Entity\User::load($current_user->id());
$name = $user->get('name')->value;
$user_last_name = $user->field_last_name->value;
if ($name == NULL){
$content1['#result'] = $string_modal.", гость!";
}
else {
$content1['#result'] = $string_modal. ', ' . $user_last_name. ' ' .$name;
}
$content1['#theme'] = 'form_theme';
$title = 'Сообщение';
$response->addCommand(new OpenModalDialogCommand($title, $content1, ['width' => '200', 'height' => '200']));
......
name: Link Task
package: Custom
type: module
core_version_requirement: ^8.8 || ^9
bootcamptest1.thank_you:
path: '/link-task'
defaults:
_controller: '\Drupal\link_test\Controller\LinkPage::content'
_title: 'Thanks for you answer'
requirements:
_permission: 'access content'
<?php
namespace Drupal\link_test\Controller;
use Drupal\bootcamp\Form\BootcampSettingsForm;
use Drupal\media\Entity\Media;
use Drupal\file\Entity\File;
/**
* Provides route responses for the DrupalBook module.
*/
//унаследовал класс
class LinkPage
{
public function content(){
$element = array(
'#markup' => 'Hello',
);
$media = Media::loadMultiple();
foreach ($media as $media_file){
$mid = $media_file->get('mid')->value;
$fid = $media_file->getSource()->getSourceFieldValue($media_file);
$file = File::load($fid);
$url[] = $file->url();
}
return $element;
}
}
......@@ -9,6 +9,7 @@ class DrupalLocalTask {
public function getResult($url)
{
//иньъек.зависимости протестировать
try{
// Отправка GET-запроса
$request = \Drupal::httpClient()->get($url);
......
......@@ -48,6 +48,7 @@ class MyService
{
$array_of_url = explode('/', $api_url); //разделяю адрес АПИ на массив элементов
$node_id = $array_of_url[5];
return $node_id;
}
......@@ -187,8 +188,7 @@ class MyService
}
public function createNode($row_item)
{
public function createNode($row_item) {
$api_url = (string)$row_item->url; //получаю URL будущей ноды
$type_of_node = $this->nodeType($api_url); //получаю тип ноды
$node_id = $this->nodeId($api_url);
......
......@@ -10,7 +10,7 @@ function role_node_access(\Drupal\node\NodeInterface $node, $op, \Drupal\Core\Se
//получаю тип ноды текущей
$type = $node
->bundle();
// для одного
if (in_array('redaktory', $account->getRoles())){
if ($type == 'editor' && $op == 'update') {
//Узнать uid в поле ноды
......@@ -19,14 +19,11 @@ function role_node_access(\Drupal\node\NodeInterface $node, $op, \Drupal\Core\Se
$uid_now = $account->id();
//сравниваю айдишники и если равны то разрешаю доступ на редактирование
if ($uid_now == $uid_role) {
return AccessResult::allowed();
return AccessResult::allowed(); //изменить ,, нужно ли запретить
}
}
}
// if ($type == 'editor' && $op == 'create') {
//$a =1;
// }
return AccessResult::neutral();
}
/**
* Implements hook_form_alter().
......
......@@ -10,6 +10,7 @@ use Drupal\rest\ResourceResponse;
use Drupal\user\UserInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Drupal\Core\Url;
/**
......@@ -82,7 +83,7 @@ class GetUserByEmailResource extends ResourceBase {
/**
* Responds to GET requests.
*/
public function get() {
public function get(Request $request) {
if (!$this->currentUser->hasPermission('access content')) {
throw new AccessDeniedHttpException();
}
......@@ -100,7 +101,7 @@ class GetUserByEmailResource extends ResourceBase {
];
// page = 0;
// получаю параметры текущей страницы из запроса пользователя, если нет то выставляю дефолтные значения
$request = \Drupal::request();
// $request = \Drupal::request();
$request_query = $request->query;
$request_query_array = $request_query->all();
$limit = $request_query->get('limit') ?: $this->limit;
......@@ -121,7 +122,7 @@ class GetUserByEmailResource extends ResourceBase {
$response['next_page'] = Url::createFromRequest($request)
->setOption('query', $next_page_query)
->toString(TRUE)
->getGeneratedUrl();
->getGeneratedUrl(); //протестировать
}
$response['count'] = $articles_count;
......@@ -150,26 +151,11 @@ class GetUserByEmailResource extends ResourceBase {
/** @var \Drupal\node\Entity\Node $article */
$testarrayfield = ['field_films' , 'field_species'];
foreach ($articles as $article) {
$rez_film = $this->getRelatedFilm($article,$cache);
if ($rez_film == NULL){
$rez_film = [];
}
$rez_species = $this->getRelatedSpecies($article);
if ($rez_species == NULL){
$rez_species = [];
}
$rez_vehicles = $this->getRelatedVehicles($article);
if ($rez_vehicles == NULL){
$rez_vehicles = [];
}
$rez_starships = $this->getRelatedStarships($article);
if ($rez_starships == NULL){
$rez_starships = [];
}
$rez_homeworld = $this->getRelatedHomeworld($article);
if ($rez_homeworld == NULL){
$rez_homeworld = [];
foreach ($testarrayfield as $field) {
$rez[$field] = $this->getRelated($article,$cache, $field);
}
$response['results'][] = [
......@@ -181,11 +167,11 @@ class GetUserByEmailResource extends ResourceBase {
'eye_color' => $article->get('field_eye_color')->value,
'birth_year' =>$article->get('field_birth_year')->value ,
'gender' => $article->get('field_gender')->value,
'homeworld' =>$rez_homeworld,
'films' => $rez_film,
'species' =>$rez_species,
'vehicles' =>$rez_vehicles,
'starships' =>$rez_starships,
'homeworld' =>$rez['field_homeworld'],
'films' => $rez['field_films'],
'species' =>$rez['field_species'],
'vehicles' =>$rez['field_vehicles'],
'starships' =>$rez['field_starships'],
'created' => $article->getCreatedTime(),
'edited' => $article->getChangedTime(),
'url' => $article->get('field_url')->value,
......@@ -195,56 +181,17 @@ class GetUserByEmailResource extends ResourceBase {
return (new ResourceResponse($response, 200))->addCacheableDependency($cache);
}
public function getRelatedFilm($article,&$cache){
public function getRelated($article, &$cache, $field){
$person_film = $article->field_films->referencedEntities();
foreach ($person_film as $film){
$cache->addCacheableDependency($film);
$related = $article->get($field)->referencedEntities();
foreach ($related as $value){
$cache->addCacheableDependency($value);
$res_film[] = [
$film->nid->value => $film->getTitle()
$value->id() => $value->label()
];
}
return $res_film;
}
public function getRelatedSpecies($article){
$person_spacie = $article->field_species->referencedEntities();
foreach ($person_spacie as $specie){
$res_specie[] = [
$specie->nid->value => $specie->getTitle()
];
}
return $res_specie;
}
public function getRelatedVehicles($article){
$person_vehicles = $article->field_vehicles->referencedEntities();
foreach ($person_vehicles as $vehicle){
$res_vehicles[] = [
$vehicle->nid->value => $vehicle->getTitle()
];
}
return $res_vehicles;
}
public function getRelatedStarships($article){
$person_starships = $article->field_starships->referencedEntities();
foreach ($person_starships as $starships){
$res_starships[] = [
$starships->nid->value => $starships->getTitle()
];
}
return $res_starships;
}
public function getRelatedHomeworld($article){
$person_homeworld = $article->field_homeworld->referencedEntities();
foreach ($person_homeworld as $p_h){
$res_homeworld[] = [
$p_h->nid->value => $p_h->getTitle()
];
}
return $res_homeworld;
}
public function post($data) {
if (!$this->currentUser->hasPermission('create article content')) {
......
......@@ -30,19 +30,18 @@ class ConBlock extends BlockBase{
$output = '';
$node = $this->getContextValue('node');
$term = $this->getContextValue('term');
if ($node != null){
$rss_output = [];
if (!empty($node)){
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$rss_output = $view_builder->view($node, 'teaser');
$output = \Drupal::service('renderer')->render($rss_output);
//$output = \Drupal::service('renderer')->render($rss_output);
}
else {
elseif (!empty($term)) {
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term');
$rss_output = $view_builder->view($term, 'teaser');
$output = \Drupal::service('renderer')->render($rss_output);
// $output = \Drupal::service('renderer')->render($rss_output);
}
return [
'#markup' => $output,
];
return $rss_output;
}
}
......@@ -8,6 +8,12 @@ function thanks_theme($existing, $type, $theme, $path) {
'dummy_example_first' => [
'variables' => [],
],
'test' => [
'render element' => 'element'
],
'student_registration_form' => [
'render element' => 'form'
]
];
}
/**
......@@ -18,3 +24,10 @@ function template_preprocess_dummy_example_first(&$variables) {
$date_formatter = \Drupal::service('date.formatter');
$variables['date'] = $date_formatter->format(time());
}
function thanks_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id){
if ($form_id == 'student_registration_form') {
$form['name']['#theme'] = 'test';
$form['#theme'] = 'student_registration_form';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment