Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
node_read_time
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
node_read_time
Merge requests
!27
#3455450
: Rendered the NodeCharactersReadTime and view fields
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
#3455450
: Rendered the NodeCharactersReadTime and view fields
issue/node_read_time-3455450:3455450-render-field-with
into
8.x-1.x
Overview
0
Commits
1
Pipelines
0
Changes
4
Open
kuzyawkk
requested to merge
issue/node_read_time-3455450:3455450-render-field-with
into
8.x-1.x
10 months ago
Overview
0
Commits
1
Pipelines
0
Changes
4
Expand
Closes
#3455450
0
0
Merge request reports
Compare
8.x-1.x
8.x-1.x (HEAD)
and
latest version
latest version
dff386e1
1 commit,
10 months ago
4 files
+
183
−
4
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
src/Plugin/Field/NodeCharactersReadTime.php
0 → 100644
+
37
−
0
Options
<?php
namespace
Drupal\node_read_time\Plugin\Field
;
use
Drupal\Core\Field\FieldItemList
;
use
Drupal\Core\TypedData\ComputedItemListTrait
;
/**
* Calculate the reading time with option "characters per minute" for the entity.
*
* @package Drupal\node_read_time\Plugin\Field
*/
class
NodeCharactersReadTime
extends
FieldItemList
{
use
ComputedItemListTrait
;
/**
* Computes the field value.
*/
protected
function
computeValue
():
void
{
$entity
=
$this
->
getEntity
();
$config
=
\Drupal
::
config
(
'node_read_time.settings'
)
->
get
(
'characters_reading_time'
)[
'container'
];
$reading_time
=
NULL
;
$entity_type
=
$entity
->
getType
();
if
(
isset
(
$config
[
$entity_type
])
&&
$config
[
$entity_type
][
'is_activated'
])
{
$reading_time_service
=
\Drupal
::
service
(
'node_read_time.reading_time'
);
$reading_time
=
$reading_time_service
->
collectWords
(
$entity
)
->
calculateReadingTime
(
'characters'
)
->
getReadingTime
();
// Clear the words variable.
$reading_time_service
->
setWords
(
0
);
}
$this
->
list
[
0
]
=
$this
->
createItem
(
0
,
$reading_time
);
}
}
Loading