33namespace Drupal \ui_patterns_settings \Plugin ;
44
55use Drupal \Component \Plugin \ConfigurableInterface ;
6+ use Drupal \Core \Entity \ContentEntityType ;
67use Drupal \Core \Plugin \PluginBase ;
78use Drupal \ui_patterns_settings \Definition \PatternDefinitionSetting ;
89use Symfony \Component \DependencyInjection \ContainerInterface ;
1213 */
1314abstract class PatternSettingTypeBase extends PluginBase implements ConfigurableInterface, PatternSettingTypeInterface {
1415
16+ /**
17+ * Returns a list of all entity tokens.
18+ *
19+ * @var \Drupal\ui_patterns_settings\Definition\PatternDefinitionSetting
20+ */
21+ protected function getTokens () {
22+
23+ }
24+
1525 /**
1626 * Return pattern definitions for setting .
1727 *
@@ -131,6 +141,44 @@ public function settingsPreprocess($value, array $context, PatternDefinitionSett
131141 return $ value ;
132142 }
133143
144+ /**
145+ * Returns the bind form field.
146+ *
147+ * @param array $form
148+ * The form definition array for the settings configuration form.
149+ * @param string $value
150+ * The stored default value.
151+ * @param \Drupal\ui_patterns_settings\Definition\PatternDefinitionSetting $def
152+ * The pattern definition.
153+ *
154+ * @return array
155+ * The form.
156+ */
157+ protected function bindForm (array $ form , $ value , PatternDefinitionSetting $ def ) {
158+ $ form [$ def ->getName () . "_binding " ] = [
159+ '#type ' => 'textfield ' ,
160+ '#title ' => "Binding " ,
161+ '#description ' => $ this ->t ("Binding for %label " , ['%label ' => $ def ->getLabel ()]),
162+ '#default_value ' => $ this ->getValue ($ value ),
163+ '#required ' => $ def ->getRequired (),
164+ ];
165+ $ entity_type_definations = \Drupal::entityTypeManager ()->getDefinitions ();
166+ /* @var $definition EntityTypeInterface */
167+ foreach ($ entity_type_definations as $ definition ) {
168+ if ($ definition instanceof ContentEntityType) {
169+ $ content_entity_types [] = $ definition ->id ();
170+ }
171+ }
172+ $ form [$ def ->getName () . '_token ' ] = [
173+ '#theme ' => 'token_tree_link ' ,
174+ '#token_types ' => $ content_entity_types ,
175+ '#show_restricted ' => TRUE ,
176+ '#default_value ' => $ value ,
177+ '#weight ' => 90 ,
178+ ];
179+ return $ form ;
180+ }
181+
134182 /**
135183 * {@inheritdoc}
136184 *
@@ -142,9 +190,10 @@ public function settingsPreprocess($value, array $context, PatternDefinitionSett
142190 *
143191 * @see \Drupal\Core\Block\BlockBase::blockForm()
144192 */
145- public function buildConfigurationForm (array $ form , $ value ) {
193+ public function buildConfigurationForm (array $ form , $ value, $ binding_value ) {
146194 $ def = $ this ->getPatternSettingDefinition ();
147195 $ form = $ this ->settingsForm ($ form , $ value , $ def );
196+ $ form = $ this ->bindForm ($ form , $ binding_value , $ def );
148197 return $ form ;
149198 }
150199
0 commit comments