X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Flinkit%2Fsrc%2FForm%2FAttribute%2FOverviewForm.php;fp=web%2Fmodules%2Fcontrib%2Flinkit%2Fsrc%2FForm%2FAttribute%2FOverviewForm.php;h=267dd61d5235de1830d0a479430b521bae9e2308;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/linkit/src/Form/Attribute/OverviewForm.php b/web/modules/contrib/linkit/src/Form/Attribute/OverviewForm.php new file mode 100644 index 000000000..267dd61d5 --- /dev/null +++ b/web/modules/contrib/linkit/src/Form/Attribute/OverviewForm.php @@ -0,0 +1,156 @@ +manager = $manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.linkit.attribute') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return "linkit_attribute_overview_form"; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state, ProfileInterface $linkit_profile = NULL) { + $this->linkitProfile = $linkit_profile; + + $form['plugins'] = [ + '#type' => 'table', + '#header' => [ + $this->t('Attribute'), + $this->t('Description'), + $this->t('Weight'), + $this->t('Operations'), + ], + '#empty' => $this->t('No attributes added.'), + '#tabledrag' => [ + [ + 'action' => 'order', + 'relationship' => 'sibling', + 'group' => 'plugin-order-weight', + ], + ], + ]; + + foreach ($this->linkitProfile->getAttributes() as $plugin) { + $key = $plugin->getPluginId(); + + $form['plugins'][$key]['#attributes']['class'][] = 'draggable'; + $form['plugins'][$key]['#weight'] = $plugin->getWeight(); + + $form['plugins'][$key]['label'] = [ + '#plain_text' => (string) $plugin->getLabel(), + ]; + + $form['plugins'][$key]['description'] = [ + '#plain_text' => (string) $plugin->getDescription(), + ]; + + $form['plugins'][$key]['weight'] = [ + '#type' => 'weight', + '#title' => t('Weight for @title', ['@title' => (string) $plugin->getLabel()]), + '#title_display' => 'invisible', + '#default_value' => $plugin->getWeight(), + '#attributes' => ['class' => ['plugin-order-weight']], + ]; + + $form['plugins'][$key]['operations'] = [ + '#type' => 'operations', + '#links' => [], + ]; + + $is_configurable = $plugin instanceof ConfigurableAttributeInterface; + if ($is_configurable) { + $form['plugins'][$key]['operations']['#links']['edit'] = [ + 'title' => t('Edit'), + 'url' => Url::fromRoute('linkit.attribute.edit', [ + 'linkit_profile' => $this->linkitProfile->id(), + 'plugin_instance_id' => $key, + ]), + ]; + } + + $form['plugins'][$key]['operations']['#links']['delete'] = [ + 'title' => t('Delete'), + 'url' => Url::fromRoute('linkit.attribute.delete', [ + 'linkit_profile' => $this->linkitProfile->id(), + 'plugin_instance_id' => $key, + ]), + ]; + } + + $form['actions'] = ['#type' => 'actions']; + $form['actions']['submit'] = [ + '#type' => 'submit', + '#value' => $this->t('Save'), + '#button_type' => 'primary', + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + foreach ($form_state->getValue('plugins') as $id => $plugin_data) { + if ($this->linkitProfile->getAttributes()->has($id)) { + $this->linkitProfile->getAttribute($id)->setWeight($plugin_data['weight']); + } + } + $this->linkitProfile->save(); + } + +}