Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}
}
}
Expand All @@ -54,29 +57,50 @@ 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',
];
}
}
}
}
$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',
Expand All @@ -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,
];
Expand Down Expand Up @@ -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.
*/
Expand All @@ -145,6 +173,7 @@ public function build() {
$announcement_list = $announcement_view->render();
$output .= '<div class="bg-md-teal p-4 mb-10">';
$output .= \Drupal::service('renderer')->render($announcement_list);

if ($announcement_list['#rows']) {
$announcment_count = count($announcement_list['#rows'][0]['#rows']);
if ($announcment_count > 4) {
Expand Down
29 changes: 29 additions & 0 deletions modules/access_events/access_events.module
Original file line number Diff line number Diff line change
Expand Up @@ -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';

}

Expand Down Expand Up @@ -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'.
*/
Expand Down
123 changes: 123 additions & 0 deletions modules/access_misc/access_misc.deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

}

}
}
}
Loading