Last active
November 8, 2016 15:10
-
-
Save modcab/31b714f5b11c6632be7ce44cfb462cbf to your computer and use it in GitHub Desktop.
Drupal 8 - View - Add a footer programmatically.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_views_pre_view(). | |
*/ | |
function projectname_views_pre_view(\Drupal\views\ViewExecutable $view, $display_id, array &$args) { | |
// Project - Assets - 'Add' link. | |
if ($view->id() == 'project_assets' && $display_id === 'block_1') { | |
$account = \Drupal::currentUser(); | |
// If we're in a group. | |
if (($group = \Drupal::routeMatch()->getParameter('group')) && | |
// And user has permissions to edit the group. | |
($group->hasPermission('edit group', $account))) { | |
$options = array( | |
'id' => 'area_text_custom', | |
'table' => 'views', | |
'field' => 'area_text_custom', | |
'relationship' => 'none', | |
'group_type' => 'none', | |
'admin_label' => '', | |
'empty' => TRUE, | |
'tokenize' => FALSE, | |
// Add an 'add' link for assets. | |
'content' => \Drupal\Core\Link::fromTextAndUrl( | |
t('Add'), | |
\Drupal\Core\Url::fromUri( | |
'internal:/group/' . $group->id() . '/content/add/group_node%3Alibrary_asset', | |
array('query' => [\Drupal::destination()->getAsArray() ]) | |
) | |
)->toString(), | |
'plugin_id' => 'text_custom', | |
); | |
$view->setHandler($display_id, 'footer', 'area_text_custom', $options); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment