Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
Project
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Gorodkov Denis
Project
Commits
222d0f94
Commit
222d0f94
authored
Jun 20, 2022
by
Gorodkov Denis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor local_task
parent
5ffec161
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
0 deletions
+63
-0
local_task.info.yml
app/docroot/modules/custom/local_task/local_task.info.yml
+7
-0
local_task.links.task.yml
...croot/modules/custom/local_task/local_task.links.task.yml
+4
-0
local_task.routing.yml
app/docroot/modules/custom/local_task/local_task.routing.yml
+7
-0
SwapiLocalTask.php
...dules/custom/local_task/src/Controller/SwapiLocalTask.php
+45
-0
No files found.
app/docroot/modules/custom/local_task/local_task.info.yml
0 → 100644
View file @
222d0f94
name
:
Local task
description
:
Custom task
package
:
Tasks
type
:
module
core
:
8.x
core_version_requirement
:
^8 || ^9
app/docroot/modules/custom/local_task/local_task.links.task.yml
0 → 100755
View file @
222d0f94
mymodule.node.swapi
:
route_name
:
local_task.task
title
:
Swapi
base_route
:
entity.node.canonical
app/docroot/modules/custom/local_task/local_task.routing.yml
0 → 100755
View file @
222d0f94
local_task.task
:
path
:
'
/node/{node}/swapi'
defaults
:
_controller
:
'
\Drupal\local_task\Controller\SwapiLocalTask::exampleTabContent'
_title_callback
:
'
\Drupal\Core\Entity\Controller\EntityController::title'
requirements
:
_custom_access
:
'
\Drupal\local_task\Controller\SwapiLocalTask::access'
app/docroot/modules/custom/local_task/src/Controller/SwapiLocalTask.php
0 → 100755
View file @
222d0f94
<?php
namespace
Drupal\local_task\Controller
;
use
Drupal\Core\Access\AccessResult
;
use
Drupal\Core\Controller\ControllerBase
;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\node\NodeInterface
;
class
SwapiLocalTask
extends
ControllerBase
{
public
function
exampleTabContent
(
$node
)
{
$nid
=
$node
;
$api
=
\Drupal
::
service
(
'swapi.service_swapi'
);
$node
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'node'
)
->
load
(
$nid
);
$bundle
=
$node
->
bundle
();
$swapi_id
=
$node
->
get
(
'field_swapi_id'
)
->
getValue
();
$url
=
'https://swapi.dev/api/'
.
$bundle
.
'/'
.
$swapi_id
[
0
][
'value'
];
$result
=
$api
->
setUrl
(
$url
)
->
getResponse
();
foreach
(
$result
as
$key
=>
$value
)
{
if
(
is_array
(
$value
))
{
$build
=
$build
.
"
\"
$key
\"
"
.
": [<br>"
;
foreach
(
$value
as
$value2
)
{
$build
=
$build
.
"
\"
$value2
\"
"
.
",<br>"
;
}
$build
=
$build
.
"],<br>"
;
}
else
{
$build
=
$build
.
"
\"
$key
\"
:
\"
$value
\"
,<br>"
;
}
}
$build
=
substr
(
$build
,
0
,
-
5
);
return
[
'#markup'
=>
$build
];
}
public
function
access
(
AccountInterface
$account
,
$node
)
{
$nid
=
$node
;
$node
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'node'
)
->
load
(
$nid
);
$bundle
=
$node
->
bundle
();
return
AccessResult
::
allowedIfHasPermission
(
$account
,
"edit any
$bundle
content"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment