diff --git a/modules/access_affinitygroup/src/Plugin/Block/AffinityBottomLeft.php b/modules/access_affinitygroup/src/Plugin/Block/AffinityBottomLeft.php index 756b338a..f56ca03b 100644 --- a/modules/access_affinitygroup/src/Plugin/Block/AffinityBottomLeft.php +++ b/modules/access_affinitygroup/src/Plugin/Block/AffinityBottomLeft.php @@ -42,7 +42,10 @@ public function build() { $eiids[] = $this->getEventInstances($es); foreach ($eiids as $e) { foreach ($e as $ei) { - $eiid[] = [$ei]; + $eiid[] = [ + 'id' => $ei, + 'attached_to' => 'event', + ]; } } } @@ -54,7 +57,10 @@ public function build() { $eiids[] = $this->getEventInstances($event['target_id']); foreach ($eiids as $e) { foreach ($e as $ei) { - $eiid[] = [$ei]; + $eiid[] = [ + 'id' => $ei, + 'attached_to' => 'ag', + ]; } } } @@ -62,21 +68,39 @@ public function build() { $event_list = []; if (!empty($eiid)) { foreach ($eiid as $ei) { - $ei = reset($ei); - $event = \Drupal::entityTypeManager()->getStorage('eventinstance')->load($ei); + $eid = $ei['id']; + $type = $ei['attached_to']; + $event = \Drupal::entityTypeManager()->getStorage('eventinstance')->load($eid); + + $eventseries = $event->getEventSeries(); + + // Check if event is set to share on Affinity Group page. + if ($type == 'event') { + $where = $eventseries->get('field_choose_where_to_share_this')->getValue(); + $show_on_ag_page = FALSE; + foreach ($where as $w) { + if ($w['value'] == 'on_your_affinity_group_page') { + $show_on_ag_page = TRUE; + } + } + } else { + // Event added directly to Affinity Group, so show it. + $show_on_ag_page = TRUE; + } + $event_status = $event->get('status')->getValue()[0]['value']; $event_date = $event->get('date')->getValue()[0]['value']; // Setup date in same format as today's date so I can get future events. $start_date = date_create($event_date); $edate = date_format($start_date, "Y-m-d"); $date_now = date("Y-m-d"); - if ($event_status && $date_now <= $edate) { + if ($event_status && $date_now <= $edate && $show_on_ag_page) { $series = $event->getEventSeries(); $series_title = $series->get('title')->getValue()[0]['value']; $link = [ '#type' => 'link', '#title' => $series_title, - '#url' => Url::fromUri('internal:/events/' . $ei), + '#url' => Url::fromUri('internal:/events/' . $eid), '#attributes' => [ 'class' => [ 'block', @@ -88,7 +112,7 @@ public function build() { ], ]; $link_name = \Drupal::service('renderer')->render($link)->__toString(); - $event_list[$ei] = [ + $event_list[$eid] = [ 'date' => $event_date, 'title' => $link_name, ]; @@ -135,6 +159,10 @@ public function build() { */ $nid = $node ? $node->id() : 291; + // Get field_affinity_announcements from node. + //$node = \Drupal\node\Entity\Node::load($nid); + //$ag_announcements = $node->get('field_affinity_announcements')->getValue(); + /** * Load Announcement view. */ @@ -145,6 +173,7 @@ public function build() { $announcement_list = $announcement_view->render(); $output .= '
'; $output .= \Drupal::service('renderer')->render($announcement_list); + if ($announcement_list['#rows']) { $announcment_count = count($announcement_list['#rows'][0]['#rows']); if ($announcment_count > 4) { diff --git a/modules/access_events/access_events.module b/modules/access_events/access_events.module index 47e38a8e..95c3be3f 100644 --- a/modules/access_events/access_events.module +++ b/modules/access_events/access_events.module @@ -75,6 +75,7 @@ function access_events_form_alter(&$form, FormStateInterface $form_state, $form_ $current_user = \Drupal::currentUser(); $roles = $current_user->getRoles(); + $form['#validate'][] = 'access_events_ag_validate'; } @@ -402,6 +403,34 @@ function access_events_eventseries_validate($form, FormStateInterface $form_stat } +/** + * Custom validation callback. + * + * Make sure AG is selected with proper checkboxes. + */ +function access_events_ag_validate(&$form, FormStateInterface $form_state) { + // Get the value of the field_choose_where_to_share_this field. + $values = $form_state->getValues(); + $share_options = $values['field_choose_where_to_share_this'] ?? []; + $ag = $values['field_affinity_group_node'] ?? []; + + $no_ag = TRUE; + foreach ($ag as $key => $value) { + if (is_array($value) && !empty($value['target_id'])) { + $no_ag = FALSE; + } + } + + if ($no_ag) { + foreach ($share_options as $key => $value) { + if ($value['value'] == 'email_to_your_affinity_group' || $value['value'] == 'on_your_affinity_group_page') { + $form_state->setErrorByName('field_affinity_group_node', t('You must select at least one Affinity Group when choosing to email your Affinity Groups or place the event on your Affinity Group Page.')); + } + } + } + +} + /** * Ajax callback function to replace the section with '#markup'. */ diff --git a/modules/access_misc/access_misc.deploy.php b/modules/access_misc/access_misc.deploy.php index 1a8c93f0..c695872a 100644 --- a/modules/access_misc/access_misc.deploy.php +++ b/modules/access_misc/access_misc.deploy.php @@ -157,3 +157,126 @@ function access_misc_deploy_10004() { // $cron = Drupal::service('cron'); // $cron->run(); } + +/** + * Where to share sql update. + */ +function access_misc_share_this($table, $bundle, $id, $revision_id, $delta, $where_to_share) { + \Drupal::database()->insert($table) + ->fields([ + 'bundle' => $bundle, + 'deleted' => 0, + 'entity_id' => $id, + 'revision_id' => $revision_id, + 'langcode' => 'en', + 'delta' => $delta, + 'field_choose_where_to_share_this_value' => $where_to_share, + ]) + ->execute(); +} + +/** + * Update where to choose field announcments. + */ +function access_misc_deploy_10005() { + $ann_query = \Drupal::entityQuery('node') + ->condition('type', 'access_news') + ->accessCheck(FALSE); + $announcements = $ann_query->execute(); + + $ann_ag_query = \Drupal::entityQuery('node') + ->condition('type', 'access_news') + ->condition('field_affinity_group', NULL, 'IS NOT NULL') + ->accessCheck(FALSE); + $announcements_ag = $ann_ag_query->execute(); + + foreach ($announcements as $nid) { + $revision_id = \Drupal::database()->select('node', 'n') + ->fields('n', ['vid']) + ->condition('n.nid', $nid) + ->orderBy('vid', 'DESC') + ->range(0, 1) + ->execute() + ->fetchField(); + + access_misc_share_this('node_revision__field_choose_where_to_share_this', 'access_news', $nid, $revision_id, 0, 'on_the_announcements_page'); + access_misc_share_this('node__field_choose_where_to_share_this', 'access_news', $nid, $revision_id, 0, 'on_the_announcements_page'); + + access_misc_share_this('node_revision__field_choose_where_to_share_this', 'access_news', $nid, $revision_id, 1, 'in_the_access_support_bi_weekly_digest'); + access_misc_share_this('node__field_choose_where_to_share_this', 'access_news', $nid, $revision_id, 1, 'in_the_access_support_bi_weekly_digest'); + + if (in_array($nid, $announcements_ag)) { + access_misc_share_this('node_revision__field_choose_where_to_share_this', 'access_news', $nid, $revision_id, 2, 'on_your_affinity_group_page'); + access_misc_share_this('node__field_choose_where_to_share_this', 'access_news', $nid, $revision_id, 2, 'on_your_affinity_group_page'); + } + + } + + // Reindex the announcements search API index to pick up domain access changes + $ann_index = Index::load('announcements'); + if ($ann_index) { + $ann_index->reindex(); + + // Process the indexing immediately + $indexed_count = $ann_index->indexItems(); + + return t('Announcments search index has been reindexed. Processed @count items to pick up new field.', [ + '@count' => $indexed_count, + ]); + } else { + return t('Warning: Announcments search index not found. Manual reindexing may be required.'); + } +} + +/** + * Update where to choose field events. + */ +function access_misc_deploy_10006() { + $share_table = \Drupal::database()->select('eventseries__field_choose_where_to_share_this', 's') + ->fields('s', ['entity_id']) + ->execute() + ->fetchField(); + if ($share_table === FALSE) { + $series_query = \Drupal::entityQuery('eventseries') + ->accessCheck(FALSE); + $series = $series_query->execute(); + + $series_ag_query = \Drupal::entityQuery('eventseries') + ->condition('field_affinity_group_node', NULL, 'IS NOT NULL') + ->accessCheck(FALSE); + $series_ag = $series_ag_query->execute(); + + foreach ($series as $sid) { + $table = 'eventseries__field_choose_where_to_share_this'; + $bundle = 'default'; + + $series_revision_id = \Drupal::database()->select('eventseries', 's') + ->fields('s', ['vid']) + ->condition('s.id', $sid) + ->orderBy('vid', 'DESC') + ->range(0, 1) + ->execute() + ->fetchField(); + + // Old Do not share checkbox. + $event_no_listing = \Drupal::database()->select('eventseries__field_event_no_listing', 'nl') + ->fields('nl', ['field_event_no_listing_value']) + ->condition('nl.entity_id', $sid) + ->execute() + ->fetchField(); + + // Do not share if old checkbox is checked. + if ($event_no_listing != 1 || $event_no_listing === FALSE) { + access_misc_share_this($table, $bundle, $sid, $series_revision_id, 0, 'on_the_announcements_page'); + + access_misc_share_this($table, $bundle, $sid, $series_revision_id, 1, 'in_the_access_support_bi_weekly_digest'); + + if (in_array($sid, $series_ag)) { + access_misc_share_this($table, $bundle, $sid, $series_revision_id, 2, 'on_your_affinity_group_page'); + } + + } + + } + } +} diff --git a/modules/access_news/access_news.module b/modules/access_news/access_news.module index b0c99bef..699e37ba 100644 --- a/modules/access_news/access_news.module +++ b/modules/access_news/access_news.module @@ -27,25 +27,25 @@ function access_news_views_pre_view(ViewExecutable $view, $display_id, array &$a if ($view->id() != 'access_news') { return; } - + $current_display = $view->getDisplay()->view->element['#display_id']; - + // Define which displays need domain filtering $domain_filtered_displays = [ 'block_1' => SiteTools::DOMAIN_CURRENT, 'latest_news_block' => SiteTools::DOMAIN_CURRENT, 'mrollup_list_block' => SiteTools::DOMAIN_ACCESS_SUPPORT, ]; - + // Apply domain filtering if this display is in our list if (isset($domain_filtered_displays[$current_display])) { $view_filters = $view->display_handler->getOption('filters'); - + // Determine which domain to use $domain = ($domain_filtered_displays[$current_display] === SiteTools::DOMAIN_CURRENT) ? \Drupal::service('access_misc.sitetools')->getDomainId() : $domain_filtered_displays[$current_display]; - + $view_filters['field_domain_access_target_id']['value'] = [$domain => $domain]; $view->display_handler->setOption('filters', $view_filters); } @@ -55,8 +55,30 @@ function access_news_views_pre_view(ViewExecutable $view, $display_id, array &$a * Implements hook_form_alter(). */ function access_news_form_alter(&$form, FormStateInterface $form_state, $form_id) { + + $domain = \Drupal::service('access_misc.sitetools')->getDomain(); + + if ($domain != 'access-support' && ($form_id == 'node_access_news_form' || $form_id == 'node_access_news_edit_form')) { + $form['field_affiliation']['#access'] = FALSE; + unset($form['field_choose_where_to_share_this']['widget']['#options']['in_the_access_support_bi_weekly_digest']); + } + // Suggest tags for announcements. if ($form_id == 'node_access_news_edit_form' || $form_id == 'node_access_news_form') { + // Replace title of 'Affiliation' and 'Choose where to share this Announcment' with h4 + $fields = ['field_affiliation', 'field_choose_where_to_share_this']; + + foreach ($fields as $field) { + $title = $form[$field]['widget']['#title']; + $form[$field]['widget']['#prefix'] = "

$title

"; + $form[$field]['widget']['#title'] = ""; + } + + // Replace title of 'External Link' with h4 + $el_title = $form['field_news_external_link']['widget'][0]['#title']; + $form['field_news_external_link']['widget'][0]['#prefix'] = "

$el_title

"; + $form['field_news_external_link']['widget'][0]['#title'] = ""; + $form['field_tags_replace'] = [ '#type' => 'container', '#attributes' => [ @@ -116,6 +138,8 @@ function access_news_form_alter(&$form, FormStateInterface $form_state, $form_id ]; // Attach javascript. $form['#attached']['library'][] = 'access_misc/node_add_tags'; + + $form['#validate'][] = 'access_news_ag_validate'; } if ($form_id == 'eventseries_default_add_form' || $form_id == 'eventseries_default_edit_form') { @@ -216,6 +240,34 @@ function access_news_replace_section_callback(array &$form, FormStateInterface $ return $form['field_tags_replace']; } +/** + * Custom validation callback. + * + * Make sure AG is selected with proper checkboxes. + */ +function access_news_ag_validate(&$form, FormStateInterface $form_state) { + // Get the value of the field_choose_where_to_share_this field. + $values = $form_state->getValues(); + $share_options = $values['field_choose_where_to_share_this'] ?? []; + $ag = $values['field_affinity_group_node'] ?? []; + + $no_ag = TRUE; + foreach ($ag as $key => $value) { + if (is_array($value) && !empty($value['target_id'])) { + $no_ag = FALSE; + } + } + + if ($no_ag) { + foreach ($share_options as $key => $value) { + if ($value['value'] == 'email_to_your_affinity_group' || $value['value'] == 'on_your_affinity_group_page') { + $form_state->setErrorByName('field_affinity_group_node', t('You must select at least one Affinity Group when choosing to email your Affinity Groups or place the announcment on your Affinity Group Page.')); + } + } + } + +} + /** * Custom validation callback. * @@ -415,8 +467,15 @@ function access_news_entity_update(EntityInterface $node) { function affinityGroupBroadcast(EntityInterface $node, $newsType) { $getFields = $node->getFields(); - $broadcastArray = $getFields['field_broadcast_affinity_groups']->getValue(); - if (!count($broadcastArray)) { + $broadcastArray = $getFields['field_choose_where_to_share_this']->getValue(); + $broadcast = 0; + foreach ($broadcastArray as $key => $value) { + if ($value['value'] == 'email_to_your_affinity_group') { + $broadcast = 1; + unset($broadcastArray[$key]); + } + } + if (!$broadcast) { return; } $broadcastToAGs = $broadcastArray[0]['value']; @@ -506,7 +565,7 @@ function affinityGroupBroadcast(EntityInterface $node, $newsType) { // Now emailing the group; set option broadcast off. If user wants to email again after // and edit, they will need to check the box again. - $node->set('field_broadcast_affinity_groups', [0]); + $node->set('field_choose_where_to_share_this', $broadcastArray); $node->save(); emailToAffinityGroups( @@ -682,7 +741,8 @@ function newsRangeView($fromDate, $toDate, $utmCampaign) { ->condition('field_published_date.value', $fromDate, '>=') ->condition('field_published_date.value', $toDate, '<=') ->condition('type', 'access_news') - ->condition('field_domain_source', SiteTools::DOMAIN_ACCESS_SUPPORT) + ->condition('field_domain_access', SiteTools::DOMAIN_ACCESS_SUPPORT) + ->condition('field_choose_where_to_share_this', 'in_the_access_support_bi_weekly_digest') ->accessCheck(FALSE) ->execute(); @@ -769,10 +829,25 @@ function eventsRangeView($fromDate, $toDate, $type, $type_title, $utmCampaign) $eCount += 1; $series = $enode->getEventSeries(); $series_id = $series->id(); - $no_share = $series->get('field_event_no_listing')->value; + // todo: Replace with new where to share checkbox soon. + //$no_share = $series->get('field_event_no_listing')->value; + + $where_share = $series->get('field_choose_where_to_share_this'); + $no_share = 1; + foreach ($where_share as $ws) { + if ($ws->value == 'in_the_access_support_bi_weekly_digest') { + $no_share = 0; + } + } + $recur_type = $series->get('recur_type')->value; - if ($series->field_event_type->value != $type || $no_share) { + if ($series->field_event_type->value != $type) { + continue; + } + + // Show only if marked to share in digest. + if ($no_share) { continue; } @@ -811,8 +886,15 @@ function eventsRangeView($fromDate, $toDate, $type, $type_title, $utmCampaign) $dateTimeDisp = $startEvent->format('n/j/Y g:i a') . ' - ' . $endDisplay . " " . $tz; - $body = empty($enode->description[0]) ? '' : $enode->description[0]->view('rollup_list'); - $bodyDisp = \Drupal::service('renderer')->renderPlain($body); + $summary = $series->get('field_summary')->value; + if ($summary == NULL) { + $body = empty($enode->description[0]) ? '' : $enode->description[0]->view('rollup_list'); + $body = \Drupal::service('renderer')->renderPlain($body); + } + else { + $body = '

' . $summary . '

'; + } + $bodyDisp = $body; // $location = empty($enode->location[0]) ? '' : $enode->location[0]->view('rollup_list'); // $locationDisp = \Drupal::service('renderer')->renderPlain($location); diff --git a/modules/access_misc/src/Plugin/search_api/processor/EventNoShow.php b/modules/access_news/src/Plugin/search_api/processor/EventWhereToShare.php similarity index 56% rename from modules/access_misc/src/Plugin/search_api/processor/EventNoShow.php rename to modules/access_news/src/Plugin/search_api/processor/EventWhereToShare.php index 7cb79719..1997bafe 100644 --- a/modules/access_misc/src/Plugin/search_api/processor/EventNoShow.php +++ b/modules/access_news/src/Plugin/search_api/processor/EventWhereToShare.php @@ -1,6 +1,6 @@ $this->t('Event No Show'), + 'label' => $this->t('Event Where to Share'), 'description' => $this->t('The event no show type.'), 'type' => 'string', 'processor_id' => $this->getPluginId(), ]; - $properties['search_api_custom_event_no_show'] = new ProcessorProperty($definition); + $properties['search_api_where_to_share'] = new ProcessorProperty($definition); } return $properties; @@ -50,17 +50,21 @@ public function addFieldValues(ItemInterface $item) { $fields = $item->getFields(); $fields = $this->getFieldsHelper() - ->filterForPropertyPath($fields, NULL, 'search_api_custom_event_no_show'); + ->filterForPropertyPath($fields, NULL, 'search_api_where_to_share'); foreach ($fields as $field) { $series = $entity->getEventSeries(); if (empty($series)) { return; } - $no_show = $series->get('field_event_no_listing')->getValue(); + $share = $series->get('field_choose_where_to_share_this')->getValue(); - if ($no_show != NULL) { - $field->addValue($no_show[0]['value']); + if ($share != NULL) { + foreach ($share as $value) { + if (isset($value['value'])) { + $field->addValue($value['value']); + } + } } }