Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
C
colorbox-3183921
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Issue forks
colorbox-3183921
Commits
a40ab426
Commit
a40ab426
authored
Jul 11, 2020
by
Neslee Canil Pinto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed Coding Standards in GalleryIdHelper.php
parent
026433f2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
58 deletions
+57
-58
src/GalleryIdHelper.php
src/GalleryIdHelper.php
+57
-58
No files found.
src/GalleryIdHelper.php
View file @
a40ab426
...
...
@@ -9,15 +9,15 @@ use Drupal\Core\Field\FieldItemInterface;
use
Drupal\Core\Utility\Token
;
/**
* Class GalleryIdHelper
* Class GalleryIdHelper
.
*
* @package Drupal\colorbox
*/
class
GalleryIdHelper
{
/**
* @var null
*
*/
protected
$galleryToken
=
NULL
;
...
...
@@ -42,62 +42,61 @@ class GalleryIdHelper {
$this
->
token
=
$token
;
}
/**
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* @param \Drupal\Core\Field\FieldItemInterface $item
* @param array $settings
*
* @return string
*/
public
function
generateId
(
ContentEntityInterface
$entity
,
FieldItemInterface
$item
,
array
$settings
)
{
$entity_bundle
=
$entity
->
bundle
();
$entity_type
=
$entity
->
getEntityTypeId
();
$config
=
$this
->
configFactory
->
get
(
'colorbox.settings'
);
// Build the gallery id.
$id
=
$entity
->
id
();
$entity_id
=
!
empty
(
$id
)
?
$entity_bundle
.
'-'
.
$id
:
'entity-id'
;
$field_name
=
$item
->
getParent
()
->
getName
();
switch
(
$settings
[
'colorbox_gallery'
])
{
case
'post'
:
$gallery_id
=
'gallery-'
.
$entity_id
;
break
;
case
'page'
:
$gallery_id
=
'gallery-all'
;
break
;
case
'field_post'
:
$gallery_id
=
'gallery-'
.
$entity_id
.
'-'
.
$field_name
;
break
;
case
'field_page'
:
$gallery_id
=
'gallery-'
.
$field_name
;
break
;
case
'custom'
:
$gallery_id
=
$this
->
token
->
replace
(
$settings
[
'colorbox_gallery_custom'
],
[
$entity_type
=>
$entity
,
'file'
=>
$item
],
[
'clear'
=>
TRUE
]);
break
;
default
:
$gallery_id
=
''
;
}
// If gallery id is not empty add unique per-request token to avoid.
// images being added manually to galleries.
if
(
!
empty
(
$gallery_id
)
&&
$config
->
get
(
'advanced.unique_token'
))
{
// Check if gallery token has already been set, we need to reuse.
// the token for the whole request.
if
(
is_null
(
$this
->
galleryToken
))
{
// We use a short token since randomness is not critical.
$this
->
galleryToken
=
Crypt
::
randomBytesBase64
(
8
);
}
$gallery_id
=
$gallery_id
.
'-'
.
$this
->
galleryToken
;
}
return
$gallery_id
;
/**
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* @param \Drupal\Core\Field\FieldItemInterface $item
* @param array $settings
*
* @return string
*/
public
function
generateId
(
ContentEntityInterface
$entity
,
FieldItemInterface
$item
,
array
$settings
)
{
$entity_bundle
=
$entity
->
bundle
();
$entity_type
=
$entity
->
getEntityTypeId
();
$config
=
$this
->
configFactory
->
get
(
'colorbox.settings'
);
// Build the gallery id.
$id
=
$entity
->
id
();
$entity_id
=
!
empty
(
$id
)
?
$entity_bundle
.
'-'
.
$id
:
'entity-id'
;
$field_name
=
$item
->
getParent
()
->
getName
();
switch
(
$settings
[
'colorbox_gallery'
])
{
case
'post'
:
$gallery_id
=
'gallery-'
.
$entity_id
;
break
;
case
'page'
:
$gallery_id
=
'gallery-all'
;
break
;
case
'field_post'
:
$gallery_id
=
'gallery-'
.
$entity_id
.
'-'
.
$field_name
;
break
;
case
'field_page'
:
$gallery_id
=
'gallery-'
.
$field_name
;
break
;
case
'custom'
:
$gallery_id
=
$this
->
token
->
replace
(
$settings
[
'colorbox_gallery_custom'
],
[
$entity_type
=>
$entity
,
'file'
=>
$item
],
[
'clear'
=>
TRUE
]);
break
;
default
:
$gallery_id
=
''
;
}
// If gallery id is not empty add unique per-request token to avoid.
// images being added manually to galleries.
if
(
!
empty
(
$gallery_id
)
&&
$config
->
get
(
'advanced.unique_token'
))
{
// Check if gallery token has already been set, we need to reuse.
// the token for the whole request.
if
(
is_null
(
$this
->
galleryToken
))
{
// We use a short token since randomness is not critical.
$this
->
galleryToken
=
Crypt
::
randomBytesBase64
(
8
);
}
$gallery_id
=
$gallery_id
.
'-'
.
$this
->
galleryToken
;
}
return
$gallery_id
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment