diff --git a/config/sync/core.entity_view_display.node.programme.default.yml b/config/sync/core.entity_view_display.node.programme.default.yml index 4778579f..40290249 100644 --- a/config/sync/core.entity_view_display.node.programme.default.yml +++ b/config/sync/core.entity_view_display.node.programme.default.yml @@ -97,6 +97,8 @@ content: settings: { } third_party_settings: { } hidden: + computed_projets_reference: true + computed_themes_reference: true field_actif: true field_poid: true langcode: true diff --git a/config/sync/core.extension.yml b/config/sync/core.extension.yml index 5436bf4b..ef5675a2 100644 --- a/config/sync/core.extension.yml +++ b/config/sync/core.extension.yml @@ -112,6 +112,7 @@ module: persistent_login: 0 popsu_link_block: 0 popsu_migrate: 0 + popsu_programme: 0 redirect: 0 redis: 0 responsive_image: 0 diff --git a/config/sync/views.view.programmes.yml b/config/sync/views.view.programmes.yml index 11b83d7c..5918244c 100644 --- a/config/sync/views.view.programmes.yml +++ b/config/sync/views.view.programmes.yml @@ -3,12 +3,13 @@ langcode: fr status: true dependencies: config: - - field.storage.node.field_diaporama - - image.style.medium + - field.storage.node.field_logo + - image.style.large - node.type.programme module: - image - node + - popsu_programme - user id: programmes label: Programmes @@ -358,6 +359,9 @@ display: title: false header: false fields: false + relationships: false + filters: false + filter_groups: false block_category: 'home (Views)' header: result: @@ -371,6 +375,70 @@ display: content: '@total programmes actifs' plugin_id: result fields: + field_logo: + id: field_logo + table: node__field_logo + field: field_logo + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: target_id + type: image + settings: + image_style: large + image_link: content + group_column: '' + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + plugin_id: field title: id: title table: node_field_data @@ -434,10 +502,10 @@ display: separator: ', ' field_api_classes: false plugin_id: field - field_diaporama: - id: field_diaporama - table: node__field_diaporama - field: field_diaporama + computed_projets_reference: + id: computed_projets_reference + table: node + field: computed_projets_reference relationship: none group_type: group admin_label: '' @@ -482,22 +550,127 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - click_sort_column: target_id - type: image - settings: - image_style: medium - image_link: content - group_column: '' - group_columns: { } - group_rows: true - delta_limit: 1 - delta_offset: 0 - delta_reversed: false - delta_first_last: false - multi_type: separator - separator: ', ' - field_api_classes: false - plugin_id: field + entity_type: node + plugin_id: views_computed_projets_reference + computed_themes_reference: + id: computed_themes_reference + table: node + field: computed_themes_reference + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + entity_type: node + plugin_id: views_computed_themes_reference + relationships: { } + filters: + status: + value: '1' + table: node_field_data + field: status + plugin_id: boolean + entity_type: node + entity_field: status + id: status + expose: + operator: '' + operator_limit_selection: false + operator_list: { } + group: 1 + type: + id: type + table: node_field_data + field: type + value: + programme: programme + entity_type: node + entity_field: type + plugin_id: bundle + expose: + operator_limit_selection: false + operator_list: { } + field_actif_value: + id: field_actif_value + table: node__field_actif + field: field_actif_value + relationship: none + group_type: group + admin_label: '' + operator: '=' + value: '1' + group: 1 + exposed: false + expose: + operator_id: '' + label: '' + description: '' + use_operator: false + operator: '' + operator_limit_selection: false + operator_list: { } + identifier: '' + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: { } + group_items: { } + plugin_id: boolean + filter_groups: + operator: AND + groups: + 1: AND cache_metadata: max-age: -1 contexts: @@ -506,4 +679,4 @@ display: - 'user.node_grants:view' - user.permissions tags: - - 'config:field.storage.node.field_diaporama' + - 'config:field.storage.node.field_logo' diff --git a/web/modules/custom/popsu_programme/config/schema/popsu_programme.schema.yml b/web/modules/custom/popsu_programme/config/schema/popsu_programme.schema.yml new file mode 100644 index 00000000..90fd1884 --- /dev/null +++ b/web/modules/custom/popsu_programme/config/schema/popsu_programme.schema.yml @@ -0,0 +1,6 @@ +views.field.view_computed_themes_reference: + type: views_field + label: 'Computed Themes Reference' +views.field.view_computed_projets_reference: + type: views_field + label: 'Computed Projets Reference' \ No newline at end of file diff --git a/web/modules/custom/popsu_programme/popsu_programme.info.yml b/web/modules/custom/popsu_programme/popsu_programme.info.yml new file mode 100644 index 00000000..a2867b04 --- /dev/null +++ b/web/modules/custom/popsu_programme/popsu_programme.info.yml @@ -0,0 +1,6 @@ +name: Popsu Programme +type: module +description: misc plugins for popsu's programmes. +core_version_requirement: ^8.8 || ^9 +package: Popsu +dependencies: diff --git a/web/modules/custom/popsu_programme/popsu_programme.module b/web/modules/custom/popsu_programme/popsu_programme.module new file mode 100644 index 00000000..6135fb21 --- /dev/null +++ b/web/modules/custom/popsu_programme/popsu_programme.module @@ -0,0 +1,88 @@ +id() == 'node' && $bundle === 'frontpage') { + // \Drupal::logger('materio_home')->notice('bundle: '.$bundle); + if ($entity_type->id() == 'node' && $bundle == 'programme') { + $fields['computed_themes_references'] = BaseFieldDefinition::create('entity_reference') + ->setName('computed_themes_references') + ->setLabel(t('Computed Themes References')) + ->setDescription(t('Computed Themes References.')) + // // The Entity Type this field belongs to. + ->setTargetEntityTypeId($entity_type->id()) + // // The Entity Type bundle this field belongs to. + ->setTargetBundle($bundle) + ->setSetting('target_type', 'node') + ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) + ->setComputed(TRUE) + ->setRevisionable(FALSE) + ->setTranslatable(FALSE) + ->setDisplayConfigurable('view', TRUE) + ->setDisplayOptions('view', [ + 'label' => 'hidden', + 'weight' => -5, + ]) + ->setClass(\Drupal\popsu_programme\Plugin\Field\FieldType\ComputedThemesReferences::class); + + $fields['computed_projets_references'] = BaseFieldDefinition::create('entity_reference') + ->setName('computed_projets_references') + ->setLabel(t('Computed Projets References')) + ->setDescription(t('Computed Projets References.')) + // // The Entity Type this field belongs to. + ->setTargetEntityTypeId($entity_type->id()) + // // The Entity Type bundle this field belongs to. + ->setTargetBundle($bundle) + ->setSetting('target_type', 'node') + ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) + ->setComputed(TRUE) + ->setRevisionable(FALSE) + ->setTranslatable(FALSE) + ->setDisplayConfigurable('view', TRUE) + ->setDisplayOptions('view', [ + 'label' => 'hidden', + 'weight' => -5, + ]) + ->setClass(\Drupal\popsu_programme\Plugin\Field\FieldType\ComputedProjetsReferences::class); + + return $fields; + } +} + + +/** + * Implements hook_views_data_alter(). + */ +function popsu_programme_views_data_alter(array &$data) { + if (isset($data['node'])) { + // Add the computed_themes_reference field to Views. + $data['node']['computed_themes_reference'] = [ + 'title' => t('Computed Theme References'), + 'field' => [ + 'id' => 'views_computed_themes_reference', + ], + ]; + // Add the computed_projets_reference field to Views. + $data['node']['computed_projets_reference'] = [ + 'title' => t('Computed Projets References'), + 'field' => [ + 'id' => 'views_computed_projets_reference', + ], + ]; + } +} \ No newline at end of file diff --git a/web/modules/custom/popsu_programme/src/Plugin/Field/FieldType/ComputedProjetsReferences.php b/web/modules/custom/popsu_programme/src/Plugin/Field/FieldType/ComputedProjetsReferences.php new file mode 100644 index 00000000..bf7a91c5 --- /dev/null +++ b/web/modules/custom/popsu_programme/src/Plugin/Field/FieldType/ComputedProjetsReferences.php @@ -0,0 +1,58 @@ +entityTypeManager = \Drupal::entityTypeManager(); + } + + /** + * Compute the values. + */ + protected function computeValue() { + // $query = \Drupal::entityQuery('node') + $entity = $this->getEntity(); + $storage = \Drupal::service('entity_type.manager')->getStorage('node'); + $query = $storage->getQuery() + ->condition('status', 1) + ->condition('type', 'projet') + ->condition('field_programme', $entity->id()); + $results = $query->execute(); + if ($results) { + $nids = array_values($results); + $i = 0; + foreach ($nids as $key => $nid) { + $this->list[$i] = $this->createItem($i, $nid); + $i++; + } + } + } + +} diff --git a/web/modules/custom/popsu_programme/src/Plugin/Field/FieldType/ComputedThemesReferences.php b/web/modules/custom/popsu_programme/src/Plugin/Field/FieldType/ComputedThemesReferences.php new file mode 100644 index 00000000..d0125a16 --- /dev/null +++ b/web/modules/custom/popsu_programme/src/Plugin/Field/FieldType/ComputedThemesReferences.php @@ -0,0 +1,58 @@ +entityTypeManager = \Drupal::entityTypeManager(); + } + + /** + * Compute the values. + */ + protected function computeValue() { + // $query = \Drupal::entityQuery('node') + $entity = $this->getEntity(); + $storage = \Drupal::service('entity_type.manager')->getStorage('node'); + $query = $storage->getQuery() + ->condition('status', 1) + ->condition('type', 'theme') + ->condition('field_programme', $entity->id()); + $results = $query->execute(); + if ($results) { + $nids = array_values($results); + $i = 0; + foreach ($nids as $key => $nid) { + $this->list[$i] = $this->createItem($i, $nid); + $i++; + } + } + } + +} diff --git a/web/modules/custom/popsu_programme/src/Plugin/views/field/ViewsComputedProjetsReference.php b/web/modules/custom/popsu_programme/src/Plugin/views/field/ViewsComputedProjetsReference.php new file mode 100644 index 00000000..19edecd5 --- /dev/null +++ b/web/modules/custom/popsu_programme/src/Plugin/views/field/ViewsComputedProjetsReference.php @@ -0,0 +1,46 @@ +_relationship_entities; + $projets = null; + // First check the referenced entity. + if (isset($relationship_entities['node'])) { + $node = $relationship_entities['node']; + } + else { + $node = $values->_entity; + } + + $type = get_class($node); + if ($type === 'Drupal\node\Entity\Node') { + $projets = $node->get('computed_projets_references')->getvalue(); + } + + return count($projets) . ' villes'; + } + + /** + * {@inheritdoc} + */ + public function query() { + // This function exists to override parent query function. + // Do nothing. + } +} \ No newline at end of file diff --git a/web/modules/custom/popsu_programme/src/Plugin/views/field/ViewsComputedThemesReference.php b/web/modules/custom/popsu_programme/src/Plugin/views/field/ViewsComputedThemesReference.php new file mode 100644 index 00000000..4cc1aea7 --- /dev/null +++ b/web/modules/custom/popsu_programme/src/Plugin/views/field/ViewsComputedThemesReference.php @@ -0,0 +1,46 @@ +_relationship_entities; + $themes = null; + // First check the referenced entity. + if (isset($relationship_entities['node'])) { + $node = $relationship_entities['node']; + } + else { + $node = $values->_entity; + } + + $type = get_class($node); + if ($type === 'Drupal\node\Entity\Node') { + $themes = $node->get('computed_themes_references')->getvalue(); + } + + return count($themes) . ' themes'; + } + + /** + * {@inheritdoc} + */ + public function query() { + // This function exists to override parent query function. + // Do nothing. + } +} \ No newline at end of file