DsFieldSource.php in UI Patterns 8
File
modules/ui_patterns_ds/src/Plugin/UiPatterns/Source/DsFieldSource.php
View source
<?php
namespace Drupal\ui_patterns_ds\Plugin\UiPatterns\Source;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\ds\Plugin\DsPluginManager;
use Drupal\ui_patterns\Plugin\PatternSourceBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DsFieldSource extends PatternSourceBase implements ContainerFactoryPluginInterface {
protected $dsManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, DsPluginManager $ds_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->dsManager = $ds_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('plugin.manager.ds'));
}
public function getSourceFields() {
$sources = [];
$fields = $this->dsManager
->getDefinitions();
foreach ($fields as $field) {
if (!$this
->getContextProperty('limit')) {
$sources[] = $this
->getSourceField($field['id'], $field['title']);
}
elseif (in_array($field['id'], $this
->getContextProperty('limit'))) {
$sources[] = $this
->getSourceField($field['id'], $field['title']);
}
}
return $sources;
}
}