Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fieldblock
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
fieldblock
Commits
aaa5bf5e
Commit
aaa5bf5e
authored
10 years ago
by
Marc van Gend
Browse files
Options
Downloads
Patches
Plain Diff
move the getBlockList method to the deriver class
parent
2d87c121
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/FieldBlockHelper.php
+0
-43
0 additions, 43 deletions
src/FieldBlockHelper.php
src/Plugin/Derivative/FieldBlock.php
+41
-0
41 additions, 0 deletions
src/Plugin/Derivative/FieldBlock.php
with
41 additions
and
43 deletions
src/FieldBlockHelper.php
+
0
−
43
View file @
aaa5bf5e
...
...
@@ -2,50 +2,7 @@
namespace
Drupal\fieldblock
;
use
Drupal\Core\Entity\Entity\EntityViewDisplay
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
class
FieldBlockHelper
{
use
StringTranslationTrait
;
/**
* Builds a list of fields that have been made available as a block.
*
* @return array An array of fieldblocks.
*
* @todo decide if this function should go into the fieldblock deriver class.
*/
public
static
function
fieldBlockGetBlockList
()
{
$fieldblocks
=
&
drupal_static
(
__FUNCTION__
);
if
(
!
isset
(
$fieldblocks
))
{
$fieldblocks
=
array
();
$entity_view_displays
=
EntityViewDisplay
::
loadMultiple
();
/** @var \Drupal\Core\Entity\EntityDisplayModeInterface $entity_view_display */
foreach
(
$entity_view_displays
as
$display_id
=>
$entity_view_display
)
{
$view_display_fieldblocks
=
$entity_view_display
->
getThirdPartySettings
(
'fieldblock'
);
$entity_type
=
$entity_view_display
->
get
(
'targetEntityType'
);
$bundle
=
$entity_view_display
->
get
(
'bundle'
);
$mode
=
$entity_view_display
->
get
(
'mode'
);
foreach
(
$view_display_fieldblocks
as
$field_name
=>
$field_label
)
{
$fieldblock_id
=
$display_id
.
':'
.
$field_name
;
$fieldblocks
[
$fieldblock_id
]
=
t
(
'@field field (from @type: @bundle: @mode)'
,
array
(
'@field'
=>
$field_label
,
'@type'
=>
$entity_type
,
'@bundle'
=>
$bundle
,
'@mode'
=>
$mode
,
));
}
}
}
return
$fieldblocks
;
}
}
This diff is collapsed.
Click to expand it.
src/Plugin/Derivative/FieldBlock.php
+
41
−
0
View file @
aaa5bf5e
...
...
@@ -9,6 +9,8 @@ namespace Drupal\fieldblock\Plugin\Derivative;
use
Drupal\Component\Plugin\Derivative\DeriverBase
;
use
Drupal\fieldblock\FieldBlockHelper
;
use
Drupal\Core\Entity\Entity\EntityViewDisplay
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
/**
* Provides block plugin definitions for fieldblock blocks.
...
...
@@ -16,6 +18,9 @@ use Drupal\fieldblock\FieldBlockHelper;
* @see \Drupal\fieldblock\Plugin\Block\FieldBlock
*/
class
FieldBlock
extends
DeriverBase
{
use
StringTranslationTrait
;
/**
* {@inheritdoc}
*/
...
...
@@ -29,4 +34,40 @@ class FieldBlock extends DeriverBase {
return
$this
->
derivatives
;
}
/**
* Builds a list of fields that have been made available as a block.
*
* @return array An array of fieldblocks.
*/
public
static
function
fieldBlockGetBlockList
()
{
$fieldblocks
=
&
drupal_static
(
__FUNCTION__
);
if
(
!
isset
(
$fieldblocks
))
{
$fieldblocks
=
array
();
// Get all EntityViewDisplay config entities and iterate over them.
$entity_view_displays
=
EntityViewDisplay
::
loadMultiple
();
/** @var \Drupal\Core\Entity\EntityDisplayModeInterface $entity_view_display */
foreach
(
$entity_view_displays
as
$display_id
=>
$entity_view_display
)
{
$view_display_fieldblocks
=
$entity_view_display
->
getThirdPartySettings
(
'fieldblock'
);
$entity_type
=
$entity_view_display
->
get
(
'targetEntityType'
);
$bundle
=
$entity_view_display
->
get
(
'bundle'
);
$mode
=
$entity_view_display
->
get
(
'mode'
);
foreach
(
$view_display_fieldblocks
as
$field_name
=>
$field_label
)
{
$fieldblock_id
=
$display_id
.
':'
.
$field_name
;
$fieldblocks
[
$fieldblock_id
]
=
t
(
'@field field (from @type: @bundle: @mode)'
,
array
(
'@field'
=>
$field_label
,
'@type'
=>
$entity_type
,
'@bundle'
=>
$bundle
,
'@mode'
=>
$mode
,
));
}
}
}
return
$fieldblocks
;
}
}
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