tested shared Vuex store, created d8 userblock, enabled JSONAPI module

This commit is contained in:
2019-04-11 00:12:23 +02:00
parent 33764c382f
commit ef76fc2596
17 changed files with 442 additions and 60 deletions

View File

@@ -0,0 +1,83 @@
<?php
namespace Drupal\user_block\Plugin\Block;
use Drupal\Core\Session\AccountProxy;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Url;
/**
* Provides a 'UserBlock' block.
*
* @Block(
* id = "user_block",
* admin_label = @Translation("User block"),
* )
*/
class UserBlock extends BlockBase implements ContainerFactoryPluginInterface{
protected $user;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
// Instantiates this form class.
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('current_user')
);
}
/**
* @param array $configuration
* @param string $plugin_id
* @param mixed $plugin_definition
* @param \Drupal\Core\Session\AccountProxyInterface $account
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountProxyInterface $account) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->user = $account;
}
/**
* {@inheritdoc}
*/
public function build() {
$build = [];
// dpm($this->user);
if($this->user->id()){
$user_url = Url::fromRoute('entity.user.canonical', ['user' => $this->user->id()]);
$build['user-link'] = array(
'#title' => $this->user->getEmail(),
'#type' => 'link',
'#url' => $user_url,
'#options'=>array(
'attributes' => array(
'data-drupal-link-system-path' => $user_url->getInternalPath(),
'alt' => t('User account'),
)
)
);
$logout_url = Url::fromRoute('user.logout');
$build['user-logout'] = array(
'#title' => t('Logout'),
'#type' => 'link',
'#url' => $logout_url,
'#options'=>array(
'attributes' => array(
'data-drupal-link-system-path' => $logout_url->getInternalPath(),
'alt' => t('Logout'),
)
)
);
}
return $build;
}
}

View File

@@ -0,0 +1,5 @@
name: 'user_block'
type: module
description: 'Provide a block with user name/email and logout link'
core: 8.x
package: 'Custom'

View File

@@ -0,0 +1,24 @@
<?php
/**
* @file
* Contains user_block.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
// function user_block_help($route_name, RouteMatchInterface $route_match) {
// switch ($route_name) {
// // Main module help for the user_block module.
// case 'help.page.user_block':
// $output = '';
// $output .= '<h3>' . t('About') . '</h3>';
// $output .= '<p>' . t('Provide a block with user name/email and logout link') . '</p>';
// return $output;
//
// default:
// }
// }