Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
manage_display
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
manage_display
Commits
afeeffe6
Commit
afeeffe6
authored
5 years ago
by
Adam Shepherd
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3104204
by AdamPS: Add submitted formatter setting for user view mode
parent
f1b27fee
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
manage_display.module
+11
-12
11 additions, 12 deletions
manage_display.module
src/Plugin/Field/FieldFormatter/SubmittedFormatter.php
+102
-3
102 additions, 3 deletions
src/Plugin/Field/FieldFormatter/SubmittedFormatter.php
templates/submitted.html.twig
+2
-3
2 additions, 3 deletions
templates/submitted.html.twig
with
115 additions
and
18 deletions
manage_display.module
+
11
−
12
View file @
afeeffe6
...
...
@@ -107,6 +107,7 @@ function manage_display_theme() {
'base hook'
=>
'username'
,
'variables'
=>
[
'date'
=>
NULL
,
'user_picture'
=>
NULL
,
'metadata'
=>
[],
'account'
=>
NULL
,
'attributes'
=>
[],
...
...
@@ -120,18 +121,6 @@ function manage_display_theme() {
* Prepares variables for 'submitted' field formatter template.
*/
function
template_preprocess_submitted
(
&
$variables
)
{
$account
=
$variables
[
'account'
];
// @todo Don't use the theme setting, instead put a setting in the formatter
// to choose a display mode (don't hard-code to 'compact').
// Hence hide the GUI for features.node_user_picture.
if
(
theme_get_setting
(
'features.node_user_picture'
))
{
// To change user picture settings (e.g. image style), edit the 'compact'
// view mode on the User entity. Note that the 'compact' view mode might
// not be configured, so remember to always check the theme setting first.
$variables
[
'author_picture'
]
=
user_view
(
$account
,
'compact'
);
}
$variables
[
'date'
]
=
\Drupal
::
service
(
'date.formatter'
)
->
format
(
$variables
[
'date'
]);
}
...
...
@@ -142,3 +131,13 @@ function manage_display_form_node_type_form_alter(&$form, FormStateInterface $fo
// Hide display_submitted in GUI.
$form
[
'display'
][
'#access'
]
=
FALSE
;
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function
manage_display_form_system_theme_settings_alter
(
&
$form
,
FormStateInterface
$form_state
,
$form_id
)
{
// Hide the theme settings for user_pictures because the submitted formatter
// has its own setting.
$form
[
'theme_settings'
][
'toggle_node_user_picture'
][
'#access'
]
=
FALSE
;
//$form['theme_settings']['toggle_comment_user_picture']['#access'] = FALSE;
}
This diff is collapsed.
Click to expand it.
src/Plugin/Field/FieldFormatter/SubmittedFormatter.php
+
102
−
3
View file @
afeeffe6
...
...
@@ -2,8 +2,12 @@
namespace
Drupal\manage_display\Plugin\Field\FieldFormatter
;
use
Drupal\Core\Entity\EntityDisplayRepositoryInterface
;
use
Drupal\Core\Field\FieldDefinitionInterface
;
use
Drupal\Core\Field\FieldItemListInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\user\Plugin\Field\FieldFormatter\AuthorFormatter
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* A field formatter for entity titles.
...
...
@@ -18,15 +22,110 @@ use Drupal\user\Plugin\Field\FieldFormatter\AuthorFormatter;
*/
class
SubmittedFormatter
extends
AuthorFormatter
{
/**
* The entity display repository.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
protected
$entityDisplayRepository
;
/**
* Constructs a EntityReferenceEntityFormatter instance.
*
* @param string $plugin_id
* The plugin_id for the formatter.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
* The definition of the field to which the formatter is associated.
* @param array $settings
* The formatter settings.
* @param string $label
* The formatter label display setting.
* @param string $view_mode
* The view mode.
* @param array $third_party_settings
* Any third party settings settings.
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
* The entity display repository.
*/
public
function
__construct
(
$plugin_id
,
$plugin_definition
,
FieldDefinitionInterface
$field_definition
,
array
$settings
,
$label
,
$view_mode
,
array
$third_party_settings
,
EntityDisplayRepositoryInterface
$entity_display_repository
)
{
parent
::
__construct
(
$plugin_id
,
$plugin_definition
,
$field_definition
,
$settings
,
$label
,
$view_mode
,
$third_party_settings
);
$this
->
entityDisplayRepository
=
$entity_display_repository
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
return
new
static
(
$plugin_id
,
$plugin_definition
,
$configuration
[
'field_definition'
],
$configuration
[
'settings'
],
$configuration
[
'label'
],
$configuration
[
'view_mode'
],
$configuration
[
'third_party_settings'
],
$container
->
get
(
'entity_display.repository'
)
);
}
/**
* {@inheritdoc}
*/
public
static
function
defaultSettings
()
{
$options
=
parent
::
defaultSettings
();
$options
[
'user_picture'
]
=
''
;
return
$options
;
}
/**
* {@inheritdoc}
*/
public
function
settingsForm
(
array
$form
,
FormStateInterface
$form_state
)
{
$form
=
parent
::
settingsForm
(
$form
,
$form_state
);
$view_modes
=
[
''
=>
$this
->
t
(
'- None -'
)];
$view_modes
+=
$this
->
entityDisplayRepository
->
getViewModeOptions
(
$this
->
getFieldSetting
(
'target_type'
));
$form
[
'user_picture'
]
=
[
'#type'
=>
'select'
,
'#options'
=>
$view_modes
,
'#title'
=>
$this
->
t
(
'View mode for user picture'
),
'#default_value'
=>
$this
->
getSetting
(
'user_picture'
),
];
return
$form
;
}
/**
* {@inheritdoc}
*/
public
function
settingsSummary
()
{
$summary
=
[];
if
(
$view_mode
=
$this
->
getSetting
(
'user_picture'
))
{
$view_modes
=
$this
->
entityDisplayRepository
->
getViewModeOptions
(
$this
->
getFieldSetting
(
'target_type'
));
$summary
[]
=
t
(
'User picture view mode: @mode'
,
[
'@mode'
=>
$view_modes
[
$view_mode
]
??
$view_mode
]);
}
else
{
$summary
[]
=
t
(
'No user picture'
);
}
return
$summary
;
}
/**
* {@inheritdoc}
*/
public
function
viewElements
(
FieldItemListInterface
$items
,
$langcode
)
{
$elements
=
parent
::
viewElements
(
$items
,
$langcode
);
foreach
(
$elements
as
$delta
=>
$entity
)
{
$elements
[
$delta
][
'#theme'
]
=
'submitted'
;
$elements
[
$delta
][
'#date'
]
=
$items
->
getEntity
()
->
get
(
'created'
)
->
value
??
NULL
;
foreach
(
$elements
as
&
$element
)
{
$element
[
'#theme'
]
=
'submitted'
;
$element
[
'#date'
]
=
$items
->
getEntity
()
->
get
(
'created'
)
->
value
??
NULL
;
if
(
$view_mode
=
$this
->
getSetting
(
'user_picture'
))
{
$element
[
'#user_picture'
]
=
user_view
(
$element
[
'#account'
],
$view_mode
);
}
}
return
$elements
;
...
...
This diff is collapsed.
Click to expand it.
templates/submitted.html.twig
+
2
−
3
View file @
afeeffe6
...
...
@@ -8,8 +8,7 @@
* contents of username.html.twig.
*
* Available variables:
* - author_picture: The author user entity, rendered using the "compact"
* view mode.
* - user_picture: The rendered author user entity
* - metadata: Metadata for this entity.
* - date: Creation date field.
* - author_attributes: HTML attributes for the containing element.
...
...
@@ -34,7 +33,7 @@
*/
#}
<footer>
{{
autho
r_picture
}}
{{
use
r_picture
}}
<div
{{
author_attributes
}}
>
{%
if
link_path
-
%}
{%
if
date
-
%}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment