Ver código fonte

on home display count villes & themes #1306. Added programme's logo from content (instead of css #1415

bach 2 anos atrás
pai
commit
45fc1bd57a

+ 2 - 0
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

+ 1 - 0
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

+ 194 - 21
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,10 +375,10 @@ display:
           content: '@total programmes actifs'
           plugin_id: result
       fields:
-        title:
-          id: title
-          table: node_field_data
-          field: title
+        field_logo:
+          id: field_logo
+          table: node__field_logo
+          field: field_logo
           relationship: none
           group_type: group
           admin_label: ''
@@ -419,11 +423,12 @@ display:
           hide_empty: false
           empty_zero: false
           hide_alter_empty: true
-          click_sort_column: value
-          type: string
+          click_sort_column: target_id
+          type: image
           settings:
-            link_to_entity: true
-          group_column: value
+            image_style: large
+            image_link: content
+          group_column: ''
           group_columns: {  }
           group_rows: true
           delta_limit: 0
@@ -434,10 +439,10 @@ display:
           separator: ', '
           field_api_classes: false
           plugin_id: field
-        field_diaporama:
-          id: field_diaporama
-          table: node__field_diaporama
-          field: field_diaporama
+        title:
+          id: title
+          table: node_field_data
+          field: title
           relationship: none
           group_type: group
           admin_label: ''
@@ -482,15 +487,14 @@ display:
           hide_empty: false
           empty_zero: false
           hide_alter_empty: true
-          click_sort_column: target_id
-          type: image
+          click_sort_column: value
+          type: string
           settings:
-            image_style: medium
-            image_link: content
-          group_column: ''
+            link_to_entity: true
+          group_column: value
           group_columns: {  }
           group_rows: true
-          delta_limit: 1
+          delta_limit: 0
           delta_offset: 0
           delta_reversed: false
           delta_first_last: false
@@ -498,6 +502,175 @@ display:
           separator: ', '
           field_api_classes: false
           plugin_id: field
+        computed_projets_reference:
+          id: computed_projets_reference
+          table: node
+          field: computed_projets_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_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'

+ 6 - 0
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'

+ 6 - 0
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:

+ 88 - 0
web/modules/custom/popsu_programme/popsu_programme.module

@@ -0,0 +1,88 @@
+<?php
+use Drupal\Core\Entity\EntityTypeInterface;
+use Drupal\Core\Field\BaseFieldDefinition;
+use Drupal\Core\Field\FieldStorageDefinitionInterface;
+
+// https://www.drupal.org/project/drupal/issues/2916266#comment-12301574
+
+
+/**
+ * Implement hook_entity_bundle_field_info().
+ *
+ * @param EntityTypeInterface $entity_type
+ * @param $bundle
+ * @param array $base_field_definitions
+ * @return array
+ */
+function popsu_programme_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
+// function materio_home_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
+  // $fields = array();
+  // if ($entity_type->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',
+      ],
+    ];
+  }
+}

+ 58 - 0
web/modules/custom/popsu_programme/src/Plugin/Field/FieldType/ComputedProjetsReferences.php

@@ -0,0 +1,58 @@
+<?php
+
+namespace Drupal\popsu_programme\Plugin\Field\FieldType;
+
+use Drupal\Core\Entity\FieldableEntityInterface;
+use Drupal\Core\Field\EntityReferenceFieldItemList;
+use Drupal\Core\Field\EntityReferenceFieldItemListInterface;
+use Drupal\Core\Field\FieldItemList;
+use Drupal\Core\TypedData\TypedDataInterface;
+use Drupal\Core\Field\BaseFieldDefinition;
+use Drupal\Core\TypedData\ComputedItemListTrait;
+
+// https://www.drupal.org/node/2112677
+// https://www.cornel.co/article/entity-reference-computed-field-example-drupal
+// https://www.caxy.com/blog/drupal-custom-form-and-computed-fields
+
+class ComputedProjetsReferences extends EntityReferenceFieldItemList
+{
+  use ComputedItemListTrait;
+
+  /**
+   * The entity type manager.
+   *
+   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
+   */
+  protected $entityTypeManager;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function __construct(BaseFieldDefinition $definition, $name, TypedDataInterface $parent) {
+    parent::__construct($definition, $name, $parent);
+    $this->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++;
+      }
+    }
+  }
+
+}

+ 58 - 0
web/modules/custom/popsu_programme/src/Plugin/Field/FieldType/ComputedThemesReferences.php

@@ -0,0 +1,58 @@
+<?php
+
+namespace Drupal\popsu_programme\Plugin\Field\FieldType;
+
+use Drupal\Core\Entity\FieldableEntityInterface;
+use Drupal\Core\Field\EntityReferenceFieldItemList;
+use Drupal\Core\Field\EntityReferenceFieldItemListInterface;
+use Drupal\Core\Field\FieldItemList;
+use Drupal\Core\TypedData\TypedDataInterface;
+use Drupal\Core\Field\BaseFieldDefinition;
+use Drupal\Core\TypedData\ComputedItemListTrait;
+
+// https://www.drupal.org/node/2112677
+// https://www.cornel.co/article/entity-reference-computed-field-example-drupal
+// https://www.caxy.com/blog/drupal-custom-form-and-computed-fields
+
+class ComputedThemesReferences extends EntityReferenceFieldItemList
+{
+  use ComputedItemListTrait;
+
+  /**
+   * The entity type manager.
+   *
+   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
+   */
+  protected $entityTypeManager;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function __construct(BaseFieldDefinition $definition, $name, TypedDataInterface $parent) {
+    parent::__construct($definition, $name, $parent);
+    $this->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++;
+      }
+    }
+  }
+
+}

+ 46 - 0
web/modules/custom/popsu_programme/src/Plugin/views/field/ViewsComputedProjetsReference.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace Drupal\popsu_programme\Plugin\views\field;
+
+use Drupal\views\ResultRow;
+use Drupal\views\Plugin\views\field\FieldPluginBase;
+
+/**
+ * A handler to provide proper displays for profile current company.
+ *
+ * @ingroup views_field_handlers
+ *
+ * @ViewsField("views_computed_projets_reference")
+ */
+class ViewsComputedProjetsReference extends FieldPluginBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function render(ResultRow $values) {
+    $relationship_entities = $values->_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.
+  }
+}

+ 46 - 0
web/modules/custom/popsu_programme/src/Plugin/views/field/ViewsComputedThemesReference.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace Drupal\popsu_programme\Plugin\views\field;
+
+use Drupal\views\ResultRow;
+use Drupal\views\Plugin\views\field\FieldPluginBase;
+
+/**
+ * A handler to provide proper displays for profile current company.
+ *
+ * @ingroup views_field_handlers
+ *
+ * @ViewsField("views_computed_themes_reference")
+ */
+class ViewsComputedThemesReference extends FieldPluginBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function render(ResultRow $values) {
+    $relationship_entities = $values->_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.
+  }
+}