sites_group_overrides-1.x-dev/src/FormDecorator/RelationshipForm.php
src/FormDecorator/RelationshipForm.php
<?php
declare(strict_types=1);
namespace Drupal\sites_group_overrides\FormDecorator;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\ContentEntityFormInterface;
use Drupal\form_decorator\ContentEntityFormDecoratorBase;
use Drupal\group\Entity\GroupRelationshipInterface;
/**
* Decorate group relationship forms.
*
* @FormDecorator()
*/
final class RelationshipForm extends ContentEntityFormDecoratorBase {
/**
* {@inheritdoc}
*/
public function applies(): bool {
if (!$this->inner instanceof ContentEntityFormInterface) {
return FALSE;
}
return $this->getEntity() instanceof GroupRelationshipInterface;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$return = $this->inner->save($form, $form_state);
$relationship = $this->getEntity();
if ($entity = $relationship->getEntity()) {
// Redirect to entity.
$form_state->setRedirectUrl($entity->toUrl());
}
return $return;
}
}
