diff --git a/group.info.yml b/group.info.yml index 4186be5..85cce5f 100644 --- a/group.info.yml +++ b/group.info.yml @@ -7,4 +7,6 @@ configure: 'group.settings' dependencies: - 'drupal:options' - 'entity:entity' + - 'drupal:content_moderation' + - 'drupal:workbench_moderation' - 'variationcache:variationcache' diff --git a/group.install b/group.install index c4cb24e..9f3cf33 100644 --- a/group.install +++ b/group.install @@ -588,3 +588,15 @@ function group_update_8023() { $group_type->save(TRUE); } } + +/** + * Enables content_moderation & workbench moderation modules if needed. + */ +function group_update_8026() { + if(!\Drupal::moduleHandler()->moduleExists('content_moderation')) { + \Drupal::service('module_installer')->install(['content_moderation']); + } + if(!\Drupal::moduleHandler()->moduleExists('workbench_moderation')) { + \Drupal::service('module_installer')->install(['workbench_moderation']); + } +} \ No newline at end of file diff --git a/group.views.inc b/group.views.inc index 9fd0ef7..712f3b5 100644 --- a/group.views.inc +++ b/group.views.inc @@ -15,6 +15,15 @@ function group_views_data_alter(array &$data) { // Get the data table for GroupContent entities. $data_table = $entity_types['group_content']->getDataTable(); + // Get GroupContent entities data table. 1.5 removes data table + $groupcontent_table = $entity_types['group_content']->getDataTable(); + $data[$groupcontent_table]['gid']['filter'] = [ + 'title' => t('Parent Group'), + 'help' => t('The group containing the entity.'), + 'field' => 'gid', + 'id' => 'gid', + ]; + /** @var \Drupal\group\Plugin\GroupContentEnablerManagerInterface $plugin_manager */ $plugin_manager = \Drupal::service('plugin.manager.group_content_enabler'); diff --git a/src/Entity/Access/GroupLatestRevisionCheck.php b/src/Entity/Access/GroupLatestRevisionCheck.php index 31d80da..9a9c78a 100644 --- a/src/Entity/Access/GroupLatestRevisionCheck.php +++ b/src/Entity/Access/GroupLatestRevisionCheck.php @@ -73,7 +73,7 @@ class GroupLatestRevisionCheck implements AccessInterface { $group = $route_match->getParameter('group'); // This tab should not show up unless there's a reason to show it. - if (!$this->moderationInfo->hasPendingRevision($group)) { + if ($this->moderationInfo && !$this->moderationInfo->hasPendingRevision($group)) { return AccessResult::forbidden('No pending revision for this group.')->addCacheableDependency($group); } diff --git a/src/Plugin/views/filter/GroupFilter.php b/src/Plugin/views/filter/GroupFilter.php new file mode 100644 index 0000000..ed0d2e2 --- /dev/null +++ b/src/Plugin/views/filter/GroupFilter.php @@ -0,0 +1,120 @@ +groupStorage = $group_storage; + $this->entityBundleInfo = $entity_type_bundle_info; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity_type.manager')->getStorage('group'), + $container->get('entity_type.bundle.info') + ); + } + + /** + * {@inheritdoc} + */ + public function getValueOptions() { + if (isset($this->options['expose']['bundles']) && $filter = $this->options['expose']['bundles']) { + $groups = $this->groupStorage->loadByProperties(['type' => $filter]); + } + else { + $groups = $this->groupStorage->loadMultiple(); + } + foreach ($groups as $group) { + $this->valueOptions[$group->id()] = $group->label(); + } + return $this->valueOptions; + } + + /** + * {@inheritdoc} + */ + public function hasExtraOptions() { + return TRUE; + } + + /** + * {@inheritdoc} + */ + public function buildExtraOptionsForm(&$form, FormStateInterface $form_state) { + $bundleList = $this->entityBundleInfo->getBundleInfo('group'); + $options = []; + foreach ($bundleList as $bundleName => $bundle) { + $options[$bundleName] = $bundle['label']; + } + $form['expose']['bundles'] = [ + '#type' => 'select', + '#title' => $this->t('Limit list to selected group types'), + '#default_value' => $this->options['expose']['bundles'] ?? NULL, + '#multiple' => TRUE, + '#options' => $options, + ]; + } + + /** + * {@inheritdoc} + */ + public function defaultExposeOptions() { + parent::defaultExposeOptions(); + $this->options['expose']['bundles'] = FALSE; + } + + /** + * {@inheritdoc} + */ + protected function defineOptions() { + $options = parent::defineOptions(); + $options['expose']['bundles'] = ['default' => NULL]; + return $options; + } + +}