Commit 16f3cc2a authored by ronaldtebrake's avatar ronaldtebrake Committed by GitHub
Browse files

Merge pull request #1989 from goalgorilla/feature/YANG-3713

Issue #3177902 by rolki, chmez, agami4, ronaldtebrake: Album feature
parents e297c733 3cfcb504
......@@ -18,5 +18,4 @@
border-bottom-left-radius: $card-border-radius;
}
}
}
......@@ -2,9 +2,11 @@
namespace Drupal\socialblue\Plugin\Preprocess;
use Drupal\Core\Url;
use Drupal\socialbase\Plugin\Preprocess\Node as NodeBase;
use Drupal\bootstrap\Utility\Element;
use Drupal\bootstrap\Utility\Variables;
use Drupal\views\Views;
/**
* Pre-processes variables for the "node" theme hook.
......@@ -20,13 +22,24 @@ class Node extends NodeBase {
*/
protected function preprocessElement(Element $element, Variables $variables) {
parent::preprocessElement($element, $variables);
/** @var \Drupal\node\Entity\Node $node */
if (theme_get_setting('style') !== 'sky') {
return;
}
/** @var \Drupal\node\NodeInterface $node */
$node = $variables['node'];
$style = theme_get_setting('style');
$view_modes = ['teaser', 'activity', 'activity_comment', 'featured', 'hero'];
$view_modes = [
'teaser',
'activity',
'activity_comment',
'featured',
'hero',
];
// Add teaser tag as title prefix to node teasers and hero view modes.
if ($style === 'sky' && in_array($variables['view_mode'], $view_modes)) {
if (in_array($variables['view_mode'], $view_modes)) {
if (!empty($variables['topic_type'])) {
$teaser_tag = $variables['topic_type'];
}
......@@ -42,8 +55,47 @@ class Node extends NodeBase {
'#template' => '<div class="teaser__tag">{{ teaser_tag }}</div>',
'#context' => ['teaser_tag' => $teaser_tag],
];
if ($node->bundle() !== 'album') {
return;
}
switch ($variables['view_mode']) {
case 'hero':
$variables['albums'] = Url::fromRoute(
'view.albums.page_albums_overview',
['user' => $node->getOwnerId()]
);
$variables['owner'] = $node->getOwner()->getDisplayName();
break;
case 'teaser':
$variables['label'] = render($variables['label']);
$variables['card_link_label'] = $this->t('View album');
if (views_get_view_result('albums', 'embed_album_cover', $node->id())) {
$view = Views::getView('albums');
$view->setArguments([$node->id()]);
$view->execute('embed_album_overview');
$variables['images_count'] = $view->total_rows;
}
break;
}
}
elseif (
$variables['view_mode'] === 'full' &&
$node->bundle() === 'album' &&
!views_get_view_result('albums', 'embed_album_cover', $node->id())
) {
$variables['no_images'] = TRUE;
$url = Url::fromRoute('social_album.post', ['node' => $node->id()]);
if ($url->access()) {
$variables['link'] = $url;
}
}
}
}
......@@ -13,32 +13,51 @@ use Drupal\socialbase\Plugin\Preprocess\Page as PageBase;
*/
class Page extends PageBase {
/**
* Display merged sidebar on the left side of the following pages...
*/
const ROUTE_NAMES = [
// ...profile pages, except edit.
'user' => [
'profile.user_page.single',
'entity.user.edit_form',
],
// ...group pages, except edit and create an album.
'group' => [
'entity.group.edit_form',
'social_album.add',
],
];
/**
* {@inheritdoc}
*/
public function preprocess(array &$variables, $hook, array $info) {
parent::preprocess($variables, $hook, $info);
if (theme_get_setting('style') === 'sky') {
if (theme_get_setting('style') !== 'sky') {
return;
}
// Display merged sidebar on the left side of profile pages, except edit.
$route_match = \Drupal::routeMatch();
if ($route_match->getParameter('user') &&
$route_match->getRouteName() !== 'profile.user_page.single' &&
$route_match->getRouteName() !== 'entity.user.edit_form') {
$variables['content_attributes']->addClass('sidebar-left', 'content-merged--sky');
}
$route_match = \Drupal::routeMatch();
// Display merged sidebar on the left side of group pages, except edit.
if ($route_match->getParameter('group') && $route_match->getRouteName() !== 'entity.group.edit_form') {
$variables['content_attributes']->addClass('sidebar-left', 'content-merged--sky');
}
foreach (self::ROUTE_NAMES as $parameter_name => $route_names) {
if (
$route_match->getParameter($parameter_name) &&
!in_array($route_match->getRouteName(), $route_names)
) {
$variables['content_attributes']->addClass(
'sidebar-left',
'content-merged--sky'
);
// Add extra class if we have blocks in both complementary regions.
if ($variables['page']['complementary_top'] && $variables['page']['complementary_bottom']) {
$variables['content_attributes']->addClass('complementary-both');
break;
}
}
// Add extra class if we have blocks in both complementary regions.
if ($variables['page']['complementary_top'] && $variables['page']['complementary_bottom']) {
$variables['content_attributes']->addClass('complementary-both');
}
}
......
{% extends "node--full--sky.html.twig" %}
{% block nodefull_body %}
{% if no_images %}
<div class="text-center">
<p>{{ 'No images added to this album yet'|t }}</p>
{% if link is not empty %}
<a href="{{ link }}" class="btn btn-default btn-sm">{{ 'Add images'|t }}</a>
{% endif %}
</div>
{% else %}
{# Delete the "like_and_dislike" field from the list of excluded fields
provided by the parent template. #}
{{ content|without('field_event_address', 'field_event_location', 'field_event_type', 'book_navigation', 'flag_follow_content', 'field_event_an_enroll', 'field_enrollment_status', 'enrolled', 'enrollments_count', 'links', 'ongoing') }}
{% endif %}
{% endblock %}
{#
/**
* @file
* Default theme implementation to display a node.
*
* Available variables:
* - node: The node entity with limited access to object properties and methods.
* Only method names starting with "get", "has", or "is" and a few common
* methods such as "id", "label", and "bundle" are available. For example:
* - node.getCreatedTime() will return the node creation timestamp.
* - node.hasField('field_example') returns TRUE if the node bundle includes
* field_example. (This does not indicate the presence of a value in this
* field.)
* - node.isPublished() will return whether the node is published or not.
* Calling other methods, such as node.delete(), will result in an exception.
* See \Drupal\node\Entity\Node for a full list of public properties and
* methods for the node object.
* - label: (optional) The title of the node.
* - content: All node items. Use {{ content }} to print them all,
* or print a subset such as {{ content.field_example }}. Use
* {{ content|without('field_example') }} to temporarily suppress the printing
* of a given child element.
* - author_picture: The node author user entity, rendered using the "compact"
* view mode.
* - metadata: Metadata for this node.
* - date: (optional) Themed creation date field.
* - author_name: (optional) Themed author name field.
* - url: Direct URL of the current node.
* - display_submitted: Whether submission information should be displayed.
* - attributes: HTML attributes for the containing element.
* The attributes.class element may contain one or more of the following
* classes:
* - node: The current template type (also known as a "theming hook").
* - node--type-[type]: The current node type. For example, if the node is an
* "Article" it would result in "node--type-article". Note that the machine
* name will often be in a short form of the human readable label.
* - node--view-mode-[view_mode]: The View Mode of the node; for example, a
* teaser would result in: "node--view-mode-teaser", and
* full: "node--view-mode-full".
* The following are controlled through the node publishing options.
* - node--promoted: Appears on nodes promoted to the front page.
* - node--sticky: Appears on nodes ordered above other non-sticky nodes in
* teaser listings.
* - node--unpublished: Appears on unpublished nodes visible only to site
* admins.
* - title_attributes: Same as attributes, except applied to the main title
* tag that appears in the template.
* - content_attributes: Same as attributes, except applied to the main
* content tag that appears in the template.
* - author_attributes: Same as attributes, except applied to the author of
* the node tag that appears in the template.
* - title_prefix: Additional output populated by modules, intended to be
* displayed in front of the main title tag that appears in the template.
* - title_suffix: Additional output populated by modules, intended to be
* displayed after the main title tag that appears in the template.
* - view_mode: View mode; for example, "teaser" or "full".
* - teaser: Flag for the teaser state. Will be true if view_mode is 'teaser'.
* - page: Flag for the full page state. Will be true if view_mode is 'full'.
* - readmore: Flag for more state. Will be true if the teaser content of the
* node cannot hold the main body content.
* - logged_in: Flag for authenticated user status. Will be true when the
* current user is a logged-in member.
* - is_admin: Flag for admin user status. Will be true when the current user
* is an administrator.
*
* @see template_preprocess_node()
*
* @todo Remove the id attribute (or make it a class), because if that gets
* rendered twice on a page this is invalid CSS for example: two lists
* in different view modes.
*
* @ingroup themeable
*/
#}
{% extends "node--hero--sky.html.twig" %}
{% block card_prefix %}
<a href="{{ albums }}" class="back-to-albums">{% trans %}{{ owner }}'s Albums{% endtrans %}</a>
{% endblock %}
{% extends "node--featured--sky.html.twig" %}
{% block card_body %}{% endblock %}
{% block card_actionbar %}
{% if images_count %}
<div class="badge teaser__badge" title="{{ 'Total amount of images'| t }}">
<span class="badge__container">
<svg class="badge__icon">
<use xlink:href="#icon-image"></use>
</svg>
<span class="badge__label">
{{ images_count }}
</span>
</span>
</div>
{% endif %}
{{ parent() }}
{% endblock %}
......@@ -76,13 +76,7 @@
{% endif %}
{% block card_link %}
{% if not hide_card_link %}
<div class="card__link">
<a href="{{ url }}" rel="bookmark">{{ 'Read more'|t }}
<span class="visually-hidden">{% trans %}about {{ label }}{% endtrans %} </span>
</a>
</div>
{% endif %}
{{ parent() }}
{% endblock %}
{% endblock %}
Supports Markdown
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