Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fully loaded node entities in routes starting with /node/{node} #12

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions embargoes.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ embargoes.node.embargoes:
_title: 'View Embargoes'
requirements:
_permission: 'manage embargoes'
options:
parameters:
node:
type: entity:node

embargoes.node.embargo:
path: '/node/{node}/embargoes/{embargo_id}'
Expand All @@ -37,6 +41,10 @@ embargoes.node.embargo:
_title: 'Edit Embargo'
requirements:
_permission: 'manage embargoes'
options:
parameters:
node:
type: entity:node

embargoes.ip_access_denied:
path: '/embargoes/ip-access-denied'
Expand Down
9 changes: 5 additions & 4 deletions src/Controller/EmbargoesNodeEmbargoesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Render\Markup;
use Drupal\node\NodeInterface;

/**
* Class EmbargoesLogController.
*/
class EmbargoesNodeEmbargoesController extends ControllerBase {

public function showEmbargoes($node = NULL) {
public function showEmbargoes(NodeInterface $node = NULL) {

$embargo_ids = \Drupal::service('embargoes.embargoes')->getAllEmbargoesByNids(array($node));
$embargo_ids = \Drupal::service('embargoes.embargoes')->getAllEmbargoesByNids(array($node->id()));
if (empty($embargo_ids)) {
$markup['embargoes'] = [
'#type' => 'markup',
Expand Down Expand Up @@ -62,7 +63,7 @@ public function showEmbargoes($node = NULL) {
'exempt_ips' => $ip_range_formatted,
'exempt_users' => $formatted_exempt_users_row,
'additional_emails' => $formatted_emails,
'edit' => Markup::create("<a href='/node/{$node}/embargoes/{$embargo_id}'>Edit</a><br><a href='/admin/config/content/embargoes/settings/embargoes/{$embargo_id}/delete'>Delete</a>"),
'edit' => Markup::create("<a href='/node/{$node->id()}/embargoes/{$embargo_id}'>Edit</a><br><a href='/admin/config/content/embargoes/settings/embargoes/{$embargo_id}/delete'>Delete</a>"),
];
array_push($rows, $row);
}
Expand All @@ -76,7 +77,7 @@ public function showEmbargoes($node = NULL) {

$markup['add'] = [
'#type' => 'markup',
'#markup' => Markup::create("<p><a href='/node/{$node}/embargoes/add'>Add Embargo</a></p>"),
'#markup' => Markup::create("<p><a href='/node/{$node->id()}/embargoes/add'>Add Embargo</a></p>"),
];

return [
Expand Down
5 changes: 3 additions & 2 deletions src/Form/EmbargoesNodeEmbargoesForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\node\NodeInterface;

/**
* Class EmbargoesNodeEmbargoesForm.
Expand All @@ -20,7 +21,7 @@ public function getFormId() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $node = NULL, $embargo_id = NULL) {
public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL, $embargo_id = NULL) {


if ($embargo_id != "add") {
Expand All @@ -34,7 +35,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $node = N

$form['embargoed_node'] = array(
'#type' => 'hidden',
'#value' => $node,
'#value' => $node->id(),
);

$form['embargo_type'] = array(
Expand Down