devel_wizard-2.x-dev/templates/spell/entity_type_group/plugin-group-relation.php.twig
templates/spell/entity_type_group/plugin-group-relation.php.twig
<?php
declare(strict_types=1);
namespace Drupal\{{ module.machineName }}\Plugin\Group\Relation;
use Drupal\group\Plugin\Group\Relation\GroupRelationBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a group relation type for {{ contentEntityType.id }}.
*
* @GroupRelationType(
* id = "{{ groupRelationPlugin.id }}",
* label = @Translation("{{ contentEntityType.id }}"),
* description = @Translation("Adds {{ contentEntityType.id }} to groups both publicly and privately."),
* entity_type_id = "{{ contentEntityType.id }}",
* entity_access = TRUE,
* reference_label = @Translation("Title"),
* reference_description = @Translation("The title of the {{ contentEntityType.id }} to add to the group"),
* deriver = "{{ groupRelationPlugin.deriverClassFqn }}",
* )
*/
class {{ contentEntityType.idUpperCamel }} extends GroupRelationBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
$config = parent::defaultConfiguration();
$config['entity_cardinality'] = 1;
return $config;
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
// Disable the entity cardinality field as the functionality of this module
// relies on a cardinality of 1. We don't just hide it, though, to keep a UI
// that's consistent with other group relations.
$info = $this->t("This field has been disabled by the plugin to guarantee the functionality that's expected of it.");
$form['entity_cardinality']['#disabled'] = TRUE;
$form['entity_cardinality']['#description'] .= '<br /><em>' . $info . '</em>';
return $form;
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
$dependencies = parent::calculateDependencies();
$dependencies['config'][] = '{{ configEntityType.definition.provider }}.{{ configEntityType.definition.get('config_prefix') }}.' . $this->getRelationType()->getEntityBundle();
return $dependencies;
}
}
