Skip to content

Instantly share code, notes, and snippets.

@nonom
Last active June 7, 2023 13:28
Show Gist options
  • Save nonom/e6a57ecc5af72bc9918ea1490f1bc67c to your computer and use it in GitHub Desktop.
Save nonom/e6a57ecc5af72bc9918ea1490f1bc67c to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace Drupal\darwin_co_authors\Plugin\FormAlter;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\pluginformalter\Plugin\FormAlterBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Darwin co-authors node form plugin.
*
* @FormAlter(
* id = "darwin_co_authors_form_alter_node",
* label = @Translation("Altering Darwin co-authors node form view."),
* form_id = {
* "node_form",
* },
* )
*
* @package Drupal\darwin_co_authors\Plugin\FormAlter
*/
class CoAuthorEntityFormPlugin extends FormAlterBase implements ContainerFactoryPluginInterface {
/**
* Constructs a form alter instance.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition
);
}
/**
* {@inheritdoc}
*/
public function formAlter(array &$form, FormStateInterface &$form_state, $form_id) {
if (isset($form['co_authors'])) {
$form['co_authors']['#group'] = 'author';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment