Skip to content

Commit

Permalink
Merge pull request #908 from rosiel/add-form-improvements-2
Browse files Browse the repository at this point in the history
Add (media/child) form improvements 2
  • Loading branch information
nigelgbanks authored Dec 14, 2022
2 parents db31d14 + 386ba0c commit f780c69
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/Controller/ManageMediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\RouteMatch;
use Drupal\node\Entity\Node;
use Drupal\Core\Url;
use Drupal\node\NodeInterface;

/**
Expand All @@ -25,14 +26,29 @@ class ManageMediaController extends ManageMembersController {
public function addToNodePage(NodeInterface $node) {
$field = IslandoraUtils::MEDIA_OF_FIELD;

return $this->generateTypeList(
$add_media_list = $this->generateTypeList(
'media',
'media_type',
'entity.media.add_form',
'entity.media_type.add_form',
$field,
['query' => ["edit[$field][widget][0][target_id]" => $node->id()]]
);

$manage_link = Url::fromRoute('entity.media_type.collection')->toRenderArray();
$manage_link['#title'] = $this->t('Manage media types');
$manage_link['#type'] = 'link';
$manage_link['#prefix'] = ' ';
$manage_link['#suffix'] = '.';

return [
'#type' => 'markup',
'#markup' => $this->t("The following media types can be added because they have the <code>@field</code> field.", [
'@field' => $field,
]),
'manage_link' => $manage_link,
'add_media' => $add_media_list,
];
}

/**
Expand Down
19 changes: 18 additions & 1 deletion src/Controller/ManageMembersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Entity\Controller\EntityController;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\islandora\IslandoraUtils;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -88,14 +89,30 @@ public static function create(ContainerInterface $container) {
*/
public function addToNodePage(NodeInterface $node) {
$field = IslandoraUtils::MEMBER_OF_FIELD;
return $this->generateTypeList(

$add_node_list = $this->generateTypeList(
'node',
'node_type',
'node.add',
'node.type_add',
$field,
['query' => ["edit[$field][widget][0][target_id]" => $node->id()]]
);

$manage_link = Url::fromRoute('entity.node_type.collection')->toRenderArray();
$manage_link['#title'] = $this->t('Manage content types');
$manage_link['#type'] = 'link';
$manage_link['#prefix'] = ' ';
$manage_link['#suffix'] = '.';

return [
'#type' => 'markup',
'#markup' => $this->t("The following content types can be added because they have the <code>@field</code> field.", [
'@field' => $field,
]),
'manage_link' => $manage_link,
'add_node' => $add_node_list,
];
}

/**
Expand Down

0 comments on commit f780c69

Please sign in to comment.