Commit a86088c0 authored by Gorodkov Denis's avatar Gorodkov Denis

commit

parent eb1eb29f
......@@ -7,7 +7,27 @@ use Drupal\node\NodeInterface;
use Drupal\Core\Access\AccessResult;
class SwapiLinkTask extends ControllerBase {
public function exampleTabContent() {
return ['#markup' => 'Content from swapi'];
public function exampleTabContent($node) {
$nid = $node;
$api = \Drupal::service('mymodule.custom_services');
$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
$bundle = $node->bundle();
$swapi_id = $node->get('field_swapi_id')->getValue();
$uri = 'https://swapi.dev/api/' . $bundle . '/' . $swapi_id[0]['value'];
$result = $api->getResponse($uri);
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];
}
}
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