diff --git a/modules/opencase_entities/oc_equal_opps.page.inc b/modules/opencase_entities/oc_equal_opps.page.inc new file mode 100644 index 0000000..6179af6 --- /dev/null +++ b/modules/opencase_entities/oc_equal_opps.page.inc @@ -0,0 +1,30 @@ +get('oc_actor')->entity->get('name')->first()->value; + $this->setName($name); + } + /** + * {@inheritdoc} + */ + public function getName() { + return $this->get('name')->value; + } + + /** + * {@inheritdoc} + */ + public function setName($name) { + $this->set('name', $name); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getCreatedTime() { + return $this->get('created')->value; + } + + /** + * {@inheritdoc} + */ + public function setCreatedTime($timestamp) { + $this->set('created', $timestamp); + return $this; + } + + /** + * {@inheritdoc} + */ + public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { + $fields = parent::baseFieldDefinitions($entity_type); + + // Add the published field. + $fields += static::publishedBaseFieldDefinitions($entity_type); + + $fields['name'] = BaseFieldDefinition::create('string') + ->setLabel(t('Name')) + ->setDescription(t('The name of the Equal Opps entity.')) + ->setSettings([ + 'max_length' => 50, + 'text_processing' => 0, + ]); + + $fields['oc_actor'] = \Drupal\Core\Field\BaseFieldDefinition::create('entity_reference') + ->setLabel(t('Person')) + ->setDescription(t('The person this pertains to.')) + ->setSetting('target_type', 'oc_actor') + ->setSetting('handler', 'default') + ->setCardinality(1) + ->setDisplayOptions('view', [ + 'type' => 'string', + 'weight' => -3, + ]) + ->setDisplayOptions('form', [ + 'type' => 'entity_reference_autocomplete_tags', + 'weight' => -3, + ]) + ->setRequired(TRUE); + + $fields['status']->setDescription(t('A boolean indicating whether the Equal Opps is published.')); + + $fields['created'] = BaseFieldDefinition::create('created') + ->setLabel(t('Created')) + ->setDescription(t('The time that the entity was created.')); + + $fields['changed'] = BaseFieldDefinition::create('changed') + ->setLabel(t('Changed')) + ->setDescription(t('The time that the entity was last edited.')); + + return $fields; + } + +} diff --git a/modules/opencase_entities/src/Entity/OCEqualOppsInterface.php b/modules/opencase_entities/src/Entity/OCEqualOppsInterface.php new file mode 100644 index 0000000..902d58a --- /dev/null +++ b/modules/opencase_entities/src/Entity/OCEqualOppsInterface.php @@ -0,0 +1,58 @@ +account = $container->get('current_user'); + return $instance; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state) { + /* @var \Drupal\opencase_entities\Entity\OCEqualOpps $entity */ + $form = parent::buildForm($form, $form_state); + + return $form; + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + $entity = $this->entity; + + $status = parent::save($form, $form_state); + + switch ($status) { + case SAVED_NEW: + $this->messenger()->addMessage($this->t('Created the %label Equal Opps.', [ + '%label' => $entity->label(), + ])); + break; + + default: + $this->messenger()->addMessage($this->t('Saved the %label Equal Opps.', [ + '%label' => $entity->label(), + ])); + } + $form_state->setRedirect('entity.oc_equal_opps.canonical', ['oc_equal_opps' => $entity->id()]); + } + +} diff --git a/modules/opencase_entities/src/Form/OCEqualOppsSettingsForm.php b/modules/opencase_entities/src/Form/OCEqualOppsSettingsForm.php new file mode 100644 index 0000000..ad4c450 --- /dev/null +++ b/modules/opencase_entities/src/Form/OCEqualOppsSettingsForm.php @@ -0,0 +1,53 @@ +isPublished()) { + return AccessResult::allowedIfHasPermission($account, 'view unpublished equal opps entities'); + } + + + return AccessResult::allowedIfHasPermission($account, 'view published equal opps entities'); + + case 'update': + + return AccessResult::allowedIfHasPermission($account, 'edit equal opps entities'); + + case 'delete': + + return AccessResult::allowedIfHasPermission($account, 'delete equal opps entities'); + } + + // Unknown operation, no opinion. + return AccessResult::neutral(); + } + + /** + * {@inheritdoc} + */ + protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { + return AccessResult::allowedIfHasPermission($account, 'add equal opps entities'); + } + + +} diff --git a/modules/opencase_entities/src/OCEqualOppsHtmlRouteProvider.php b/modules/opencase_entities/src/OCEqualOppsHtmlRouteProvider.php new file mode 100644 index 0000000..2a4d64c --- /dev/null +++ b/modules/opencase_entities/src/OCEqualOppsHtmlRouteProvider.php @@ -0,0 +1,56 @@ +id(); + + if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) { + $collection->add("$entity_type_id.settings", $settings_form_route); + } + + return $collection; + } + + /** + * Gets the settings form route. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type. + * + * @return \Symfony\Component\Routing\Route|null + * The generated route, if available. + */ + protected function getSettingsFormRoute(EntityTypeInterface $entity_type) { + if (!$entity_type->getBundleEntityType()) { + $route = new Route("/admin/structure/{$entity_type->id()}/settings"); + $route + ->setDefaults([ + '_form' => 'Drupal\opencase_entities\Form\OCEqualOppsSettingsForm', + '_title' => "{$entity_type->getLabel()} settings", + ]) + ->setRequirement('_permission', $entity_type->getAdminPermission()) + ->setOption('_admin_route', TRUE); + + return $route; + } + } + +} diff --git a/modules/opencase_entities/src/OCEqualOppsListBuilder.php b/modules/opencase_entities/src/OCEqualOppsListBuilder.php new file mode 100644 index 0000000..c73bb3e --- /dev/null +++ b/modules/opencase_entities/src/OCEqualOppsListBuilder.php @@ -0,0 +1,39 @@ +t('Equal Opps ID'); + $header['name'] = $this->t('Name'); + return $header + parent::buildHeader(); + } + + /** + * {@inheritdoc} + */ + public function buildRow(EntityInterface $entity) { + /* @var \Drupal\opencase_entities\Entity\OCEqualOpps $entity */ + $row['id'] = $entity->id(); + $row['name'] = Link::createFromRoute( + $entity->label(), + 'entity.oc_equal_opps.edit_form', + ['oc_equal_opps' => $entity->id()] + ); + return $row + parent::buildRow($entity); + } + +} diff --git a/modules/opencase_entities/templates/oc_equal_opps.html.twig b/modules/opencase_entities/templates/oc_equal_opps.html.twig new file mode 100644 index 0000000..5bb23a6 --- /dev/null +++ b/modules/opencase_entities/templates/oc_equal_opps.html.twig @@ -0,0 +1,22 @@ +{# +/** + * @file oc_equal_opps.html.twig + * Default theme implementation to present Equal Opps data. + * + * This template is used when viewing Equal Opps pages. + * + * + * Available variables: + * - content: A list of content items. Use 'content' to print all content, or + * - attributes: HTML attributes for the container element. + * + * @see template_preprocess_oc_equal_opps() + * + * @ingroup themeable + */ +#} + + {% if content %} + {{- content -}} + {% endif %} + diff --git a/opencase.links.menu.yml b/opencase.links.menu.yml index dc45406..516f635 100644 --- a/opencase.links.menu.yml +++ b/opencase.links.menu.yml @@ -23,6 +23,12 @@ opencase.add_events_links: deriver: Drupal\opencase\Plugin\Derivative\AddEventsMenuLink menu_name: opencase parent: opencase.opencase_add_new_things_menu +opencase.add_equal_opps: + title: 'Equal Opportunies record' + menu_name: opencase + url: internal:/opencase/oc_equal_opps/add + parent: opencase.opencase_add_new_things_menu + weight: 10 opencase.opencase_admin_menu: title: 'Administration' description: 'Management and Configuration'