Commit ee0f5ea4 authored by levmyshkin's avatar levmyshkin Committed by chris_hall_hu_cheng

Issue #2699311 by levmyshkin: Missing functionality

parent cc4fb9eb
blog.blog_all:
route_name: 'node.add'
title: 'Add blog post'
route_parameters:
node_type: 'blog_post'
appears_on:
- view.blog.blog_all
blog.blog_user_all:
route_name: 'node.add'
title: 'Add blog post'
route_parameters:
node_type: 'blog_post'
appears_on:
- view.blog.blog_user_all
\ No newline at end of file
......@@ -6,6 +6,8 @@
*/
use \Drupal\Core\Url;
use \Drupal\Core\Session;
use \Drupal\node\NodeInterface;
/**
* Implements hook_ENTITY_TYPE_view().
......@@ -50,59 +52,23 @@ function blog_help($path, $arg) {
}
/**
* Implements hook_node_view().
* Implements hook_node_links_alter().
*/
function blog_node_view(&$build, $node, $display, $view_mode) {
if ($view_mode != 'rss') {
if ($node->type == 'blog' && (arg(0) != 'blog' || arg(1) != $node->uid)) {
$links['blog_usernames_blog'] = array(
'title' => t("!username's blog", array('!username' => user_format_name($node))),
'href' => "blog/$node->uid",
'attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => user_format_name($node)))),
);
$node->content['links']['blog'] = array(
'#theme' => 'links__node__blog',
'#links' => $links,
'#attributes' => array('class' => array('links', 'inline')),
);
}
}
}
function blog_node_links_alter(array &$node_links, NodeInterface $entity, array &$context) {
if ($entity->getEntityTypeId() == 'node' && $entity->bundle() == 'blog_post' && $context['view_mode'] != 'rss') {
/**
* Implements hook_menu_local_tasks_alter().
*/
function blog_menu_local_tasks_alter(&$data, $route_name) {
//Get the account for the current user.
$account = \Drupal::currentUser();
//Get user from arg if present
$user = \Drupal::routeMatch()->getParameter('user');
// Add action link to 'node/add/blog' on 'blog' page.
if ($route_name == 'view.blog.blog_user_all') {
if (\Drupal::service('path.validator')->isValid('node/add/blog_post')) {
$data['actions']['output'][] = array(
'#theme' => 'menu_local_action',
'#link' => array(
'title' => t('Create new blog post'),
'href' => 'node/add/blog',
),
);
}
}
// Provide a helper action link to the author on the 'blog/%' page.
elseif ($route_name == 'view.blog.blog_user_all' && !empty($user) && $account->id() == $user->id()) {
$data['actions']['output']['blog'] = array(
'#theme' => 'menu_local_action',
$links['blog_usernames_blog'] = array(
'title' => t("username's Blog", array('username' => $entity->getOwner()->getDisplayName())),
'url' => Url::fromRoute('view.blog.blog_user_all', [
'arg_0' => $entity->getOwnerId(),
]),
'attributes' => array('title' => t("Read username's latest blog entries.", array('username' => $entity->getOwner()->getDisplayName()))),
);
$node_links['usernames_blog'] = array(
'#theme' => 'links__node__blog',
'#links' => $links,
'#attributes' => array('class' => array('links', 'inline')),
);
if ($account->hasPermission('create blog content')) {
$data['actions']['output']['blog']['#link']['title'] = t('Post new blog entry.');
$data['actions']['output']['blog']['#link']['href'] = 'node/add/blog';
}
else {
$data['actions']['output']['blog']['#link']['title'] = t('You are not allowed to post a new blog entry.');
}
}
}
......
......@@ -249,7 +249,7 @@ display:
title_enable: false
title: All
title_enable: true
title: '{{ arguments.uid }}''s Blog'
title: '{{ arguments.uid }}''s blog'
default_argument_type: fixed
default_argument_options:
argument: ''
......@@ -313,8 +313,10 @@ display:
type: rss
path: blog/feed
displays:
default: default
page_1: page_1
blog_all: blog_all
default: '0'
blog_block: '0'
blog_user_all: '0'
display_description: ''
cache_metadata:
max-age: -1
......@@ -337,10 +339,12 @@ display:
type: some
style:
type: rss
path: blog/feed
path: blog/%/feed
displays:
default: default
page_1: page_1
blog_user_all: blog_user_all
default: '0'
blog_all: '0'
blog_block: '0'
display_description: ''
arguments:
uid:
......
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