-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YALB-1438): Add profile meta block to layout
- Loading branch information
1 parent
0d1ec68
commit 7cffca6
Showing
4 changed files
with
130 additions
and
214 deletions.
There are no files selected for viewing
This file contains 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
88 changes: 88 additions & 0 deletions
88
.../custom/yalesites_profile/modules/custom/ys_layouts/src/Plugin/Block/ProfileMetaBlock.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Drupal\ys_layouts\Plugin\Block; | ||
|
||
use Drupal\Core\Block\BlockBase; | ||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Drupal\Core\Routing\RouteMatchInterface; | ||
use Drupal\node\NodeInterface; | ||
use Drupal\Core\Url; | ||
|
||
/** | ||
* Block for profile meta data that appears above profiles. | ||
* | ||
* @Block( | ||
* id = "profile_meta_block", | ||
* admin_label = @Translation("Profile Meta Block"), | ||
* category = @Translation("YaleSites Layouts"), | ||
* ) | ||
*/ | ||
class ProfileMetaBlock extends BlockBase implements ContainerFactoryPluginInterface { | ||
|
||
/** | ||
* The current route match. | ||
* | ||
* @var \Drupal\Core\Routing\RouteMatchInterface | ||
*/ | ||
protected $routeMatch; | ||
|
||
/** | ||
* Constructs a new BookNavigationBlock instance. | ||
* | ||
* @param array $configuration | ||
* A configuration array containing information about the plugin instance. | ||
* @param string $plugin_id | ||
* The plugin_id for the plugin instance. | ||
* @param mixed $plugin_definition | ||
* The plugin implementation definition. | ||
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match | ||
* The current route match. | ||
*/ | ||
public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match) { | ||
parent::__construct($configuration, $plugin_id, $plugin_definition); | ||
|
||
$this->routeMatch = $route_match; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | ||
return new static( | ||
$configuration, | ||
$plugin_id, | ||
$plugin_definition, | ||
$container->get('current_route_match') | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function build() { | ||
|
||
/** @var \Drupal\node\NodeInterface $node */ | ||
$node = $this->routeMatch->getParameter('node'); | ||
if (!($node instanceof NodeInterface)) { | ||
return []; | ||
} | ||
|
||
// Profile fields. | ||
$title = $node->getTitle(); | ||
$position = ($node->field_position->first()) ? $node->field_position->first()->getValue()['value'] : NULL; | ||
$subtitle = ($node->field_subtitle->first()) ? $node->field_subtitle->first()->getValue()['value'] : NULL; | ||
$department = ($node->field_department->first()) ? $node->field_department->first()->getValue()['value'] : NULL; | ||
$mediaId = ($node->field_media->first()) ? $node->field_media->first()->getValue()['target_id'] : NULL; | ||
|
||
return [ | ||
'#theme' => 'ys_profile_meta_block', | ||
'#name' => $title, | ||
'#position' => $position, | ||
'#subtitle' => $subtitle, | ||
'#department' => $department, | ||
'#media_id' => $mediaId, | ||
]; | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
...tom/yalesites_profile/modules/custom/ys_layouts/templates/ys-profile-meta-block.html.twig
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Name: {{ name }}<br> | ||
Position: {{ position }}<br> | ||
Subtitle: {{ subtitle }}<br> | ||
Department: {{ department }}<br> | ||
|
||
{{ drupal_entity('media', media_id, 'card_secondary_3_2') }} |
This file contains 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