diff --git a/composer.json b/composer.json index 0c8bc70ccb90c95c30ed83efc025d96974bdcf9e..0e1b6b74a386f1709eda4cc772c65a82f64f7d8a 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "source": "http://cgit.drupalcode.org/dsr_portal" }, "require": { - "drupal/dsr": "^1.0.21 || ^2.0", + "drupal/dsr": "^1.0.22-rc2 || ^2.0", "drupal/email_registration": "^1.1", "drupal/route_condition":"^2.0", "drupal/field_permissions":"^1.0" diff --git a/dsr_portal.module b/dsr_portal.module index 6ab2bf3900284da7241c9bff9a18aba6ad50087f..82f93279dc9c20f36d1fcaef83e8dd76ac6a0077 100644 --- a/dsr_portal.module +++ b/dsr_portal.module @@ -7,7 +7,9 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Session\AccountInterface; use Drupal\user\Entity\User; @@ -126,13 +128,13 @@ function dsr_portal_user_register_validate($form, &$form_state) { */ function dsr_portal_entity_type_build($entity_types) { /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ - $entity_types['shareholder']->setFormClass('portal', 'Drupal\shareholder_register\Form\ShareholderForm'); + $entity_types['shareholder']->setFormClass('portal', 'Drupal\dsr_portal\Form\ShareholderPortalForm'); } /** * Implements hook_entity_access(). */ -function dsr_portal_entity_access(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Session\AccountInterface $account) { +function dsr_portal_entity_access(EntityInterface $entity, $operation, AccountInterface $account) { if ($entity->getEntityTypeId() == 'shareholder') { switch ($operation) { case 'portal-view': diff --git a/src/Form/ShareholderPortalForm.php b/src/Form/ShareholderPortalForm.php new file mode 100644 index 0000000000000000000000000000000000000000..27d96f5f4cabe5f2f0f74af7b12668772d1fc459 --- /dev/null +++ b/src/Form/ShareholderPortalForm.php @@ -0,0 +1,68 @@ +<?php + +namespace Drupal\dsr_portal\Form; + +use Drupal\Core\Entity\ContentEntityForm; +use Drupal\Core\Form\FormStateInterface; + +use Drupal\shareholder_register\Form\ShareholderForm; + +/** + * Form controller for Shareholder portal edit forms. + * + * @ingroup shareholder_register + */ +class ShareholderPortalForm extends ShareholderForm { + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state) { + $form = parent::buildForm($form, $form_state); + $form['revision_log_message']['widget'][0]['#access'] = FALSE; + $form['address']['widget'][0]['address']['#address_options']['disable-name'] = TRUE; + return $form; + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + $entity = $this->entity; + + // Always save a new revision when editing a shareholder. + if (!$this->entity->isNew()) { + $entity->setNewRevision(); + + // If a new revision is created, save the current user as revision author. + $entity->setRevisionCreationTime(REQUEST_TIME); + $entity->setRevisionUserId(\Drupal::currentUser()->id()); + $entity->setRevisionLogMessage( + $this->t( + "Portal user @user (@uid) updated this shareholder.", + [ + '@user' => \Drupal::currentUser()->getDisplayName(), + '@uid' => \Drupal::currentUser()->id(), + ] + ) + ); + } + + $status = parent::save($form, $form_state); + + switch ($status) { + case SAVED_NEW: + $this->messenger()->addMessage($this->t('Created the %label Shareholder.', [ + '%label' => $entity->label(), + ])); + break; + + default: + $this->messenger()->addMessage($this->t('Saved the %label Shareholder.', [ + '%label' => $entity->label(), + ])); + } + + $form_state->setRedirect('dsr_portal.portal', ['shareholder' => $entity->id()]); + } +}