-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create an UiPatternsSource to be able to use field groups in patterns…
… fields.
- Loading branch information
Edouard Cunibil
committed
Oct 29, 2020
1 parent
cd03369
commit f17c8b2
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
modules/ui_patterns_field_group/src/Plugin/UiPatterns/Source/FieldgroupSource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Drupal\ui_patterns_field_group\Plugin\UiPatterns\Source; | ||
|
||
use Drupal\ui_patterns\Plugin\PatternSourceBase; | ||
|
||
/** | ||
* Defines Fields API pattern source plugin. | ||
* | ||
* @UiPatternsSource( | ||
* id = "fieldgroup", | ||
* label = @Translation("Fieldgroups"), | ||
* provider = "field_group", | ||
* tags = { | ||
* "entity_display" | ||
* } | ||
* ) | ||
*/ | ||
class FieldgroupSource extends PatternSourceBase { | ||
|
||
/** | ||
* Return list of source fields. | ||
* | ||
* @return \Drupal\ui_patterns\Definition\PatternSourceField[] | ||
* List of source fields. | ||
* | ||
* @throws \Drupal\Component\Plugin\Exception\PluginException | ||
*/ | ||
public function getSourceFields() { | ||
$sources = []; | ||
$entity_type_id = $this->getContextProperty('entity_type'); | ||
$bundle = $this->getContextProperty('entity_bundle'); | ||
$view_mode = $this->getContextProperty('entity_view_mode'); | ||
|
||
$groups = field_group_info_groups($entity_type_id, $bundle, 'view', $view_mode); | ||
|
||
foreach ($groups as $group_name => $group) { | ||
if (empty($this->getContextProperty('limit')) || in_array($group_name, $this->getContextProperty('limit'))) { | ||
$sources[] = $this->getSourceField($group_name, $group->label); | ||
} | ||
} | ||
|
||
return $sources; | ||
} | ||
|
||
} |