use Drupal\Core\Form\FormStateInterface; use Drupal\node\Entity\Node; /** * Implements hook_form_alter(). */ function filter_events_form_alter(&$form, FormStateInterface $form_state, $form_id) { if ( $form_id === 'views_exposed_form' && isset($form['#id']) && $form['#id'] === 'views-exposed-form-news-block-4' ) { \Drupal::logger('filter_events')->notice('Mulai mengisi select-year.'); // Ambil semua node konten news $nids = \Drupal::entityQuery('node') ->condition('type', 'news') ->condition('status', 1) ->execute(); \Drupal::logger('filter_events')->notice('Jumlah node news ditemukan: @count', [ '@count' => count($nids), ]); if (!empty($nids)) { $nodes = Node::loadMultiple($nids); $years = []; foreach ($nodes as $node) { $year = date('Y', $node->getCreatedTime()); $years[] = $year; } \Drupal::logger('filter_events')->notice('Tahun yang ditemukan: @years', [ '@years' => implode(', ', $years), ]); if (!empty($years)) { $min_year = min($years); $max_year = max($years); \Drupal::logger('filter_events')->notice('Tahun range: @min - @max', [ '@min' => $min_year, '@max' => $max_year, ]); // Generate opsi tahun $year_options = ['' => 'All']; for ($y = $max_year; $y >= $min_year; $y--) { $year_options[$y] = $y; } // Coba isi ke form exposed if (isset($form['select-year'])) { $form['select-year']['#options'] = $year_options; \Drupal::logger('filter_events')->notice('Form element select-year ditemukan di exposed form, options ditambahkan.'); } else { // Jika tidak ada, tambahkan manual $form['select-year'] = [ '#type' => 'select', '#title' => t('Year'), '#options' => $year_options, '#attributes' => ['id' => 'select-year', 'class' => ['form-control', 'form-control-sm']], '#weight' => -10, ]; \Drupal::logger('filter_events')->warning('Form element select-year TIDAK ditemukan, dibuat manual oleh hook_form_alter().'); } } } else { \Drupal::logger('filter_events')->warning('Tidak ada node news ditemukan.'); } } } https://dev.coraltriangleinitiative.org/ 2025-12-05T15:37:43+05:30 daily 1.0 https://dev.coraltriangleinitiative.org/home 2025-12-05T15:37:43+05:30 0.5 https://dev.coraltriangleinitiative.org/company 2020-11-30T16:18:12+05:30 0.5 https://dev.coraltriangleinitiative.org/our-team 2020-06-06T11:16:31+05:30 0.5 https://dev.coraltriangleinitiative.org/our-history 2020-11-26T10:36:43+05:30 0.5 https://dev.coraltriangleinitiative.org/testimonials 2020-05-07T18:39:26+05:30 0.5 https://dev.coraltriangleinitiative.org/our-clients 2020-11-26T10:24:55+05:30 0.5 https://dev.coraltriangleinitiative.org/services 2025-09-22T09:40:30+05:30 0.5 https://dev.coraltriangleinitiative.org/portfolio-grid 2020-04-16T18:07:47+05:30 0.5 https://dev.coraltriangleinitiative.org/portfolio-masonry 2020-04-16T18:26:17+05:30 0.5 https://dev.coraltriangleinitiative.org/blog-list 2020-04-16T15:19:54+05:30 0.5 https://dev.coraltriangleinitiative.org/pricing 2020-04-16T15:24:06+05:30 0.5 https://dev.coraltriangleinitiative.org/careers 2020-04-16T15:23:46+05:30 0.5 https://dev.coraltriangleinitiative.org/blog-3-grid 2020-05-05T17:29:16+05:30 0.5 https://dev.coraltriangleinitiative.org/faq 2020-11-25T19:41:02+05:30 0.5 https://dev.coraltriangleinitiative.org/contact 2025-11-19T14:09:56+05:30 0.5 https://dev.coraltriangleinitiative.org/apply-now 2020-04-15T18:42:14+05:30 0.5 https://dev.coraltriangleinitiative.org/blog-2-grid 2020-05-05T17:07:25+05:30 0.5 https://dev.coraltriangleinitiative.org/blog-4-grid 2020-05-05T17:15:06+05:30 0.5 https://dev.coraltriangleinitiative.org/blog-grid-sidebar 2020-05-05T17:56:15+05:30 0.5 https://dev.coraltriangleinitiative.org/blog-list-sidebar 2020-05-05T18:22:58+05:30 0.5 https://dev.coraltriangleinitiative.org/services-3-grid 2020-05-06T10:49:30+05:30 0.5 https://dev.coraltriangleinitiative.org/services-2-grid 2020-05-06T11:19:05+05:30 0.5 https://dev.coraltriangleinitiative.org/services-4-grid 2020-05-06T11:34:45+05:30 0.5 https://dev.coraltriangleinitiative.org/home-video-banner 2025-09-17T20:41:27+05:30 0.5 https://dev.coraltriangleinitiative.org/threats 2025-09-22T15:13:34+05:30 0.5 https://dev.coraltriangleinitiative.org/present-and-former-executive-directors 2025-09-25T08:17:11+05:30 0.5 https://dev.coraltriangleinitiative.org/test 2025-10-06T10:31:13+05:30 0.5 https://dev.coraltriangleinitiative.org/news 2025-10-09T10:25:11+05:30 0.5 https://dev.coraltriangleinitiative.org/events 2025-10-16T12:44:33+05:30 0.5 https://dev.coraltriangleinitiative.org/resources 2025-10-21T07:59:44+05:30 0.5 https://dev.coraltriangleinitiative.org/multimedia 2025-10-22T09:11:13+05:30 0.5 https://dev.coraltriangleinitiative.org/videos 2025-10-22T10:01:14+05:30 0.5 https://dev.coraltriangleinitiative.org/oportunities-vacancies 2025-12-04T13:47:21+05:30 0.5 https://dev.coraltriangleinitiative.org/search 2025-11-07T12:13:35+05:30 0.5 https://dev.coraltriangleinitiative.org/speeches 2025-11-18T15:10:41+05:30 0.5 https://dev.coraltriangleinitiative.org/calendar-events 2025-11-24T08:47:26+05:30 0.5 https://dev.coraltriangleinitiative.org/threats/food-security-crisis-coral-triangle-real-threat-neglected-sea 2025-12-05T13:31:44+05:30 0.5 https://dev.coraltriangleinitiative.org/threats/destruction-marine-ecosystems-coral-triangle-real-threat-life-and-future 2025-12-05T13:32:55+05:30 0.5 https://dev.coraltriangleinitiative.org/threats/great-economic-loss-price-pay-if-coral-triangle-collapses 2025-12-05T13:29:21+05:30 0.5