materio_home.module 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. use Drupal\Core\Entity\EntityTypeInterface;
  3. use Drupal\Core\Field\BaseFieldDefinition;
  4. use Drupal\Core\Field\FieldStorageDefinitionInterface;
  5. use Drupal\mymodule\Plugin\Field\FieldType\MyFieldComputed;
  6. /**
  7. * Implements hook_theme().
  8. */
  9. // function materio_home_theme($existing, $type, $theme, $path) {
  10. // // @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module
  11. //
  12. // return array(
  13. // 'materio_home' => array(
  14. // // 'render element' => '',
  15. // 'file' => 'includes/materio_home.inc',
  16. // 'variables' => array(
  17. // 'frontpage_node' => NULL,
  18. // ),
  19. // ),
  20. // );
  21. // }
  22. /**
  23. * Implement hook_entity_bundle_field_info().
  24. *
  25. * @param EntityTypeInterface $entity_type
  26. * @param $bundle
  27. * @param array $base_field_definitions
  28. * @return array
  29. */
  30. function materio_home_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
  31. // function materio_home_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
  32. // $fields = array();
  33. // if ($entity_type->id() == 'node' && $bundle === 'frontpage') {
  34. // \Drupal::logger('materio_home')->notice('bundle: '.$bundle);
  35. if ($entity_type->id() == 'node' && $bundle == 'frontpage') {
  36. $fields['computed_materials_reference'] = BaseFieldDefinition::create('entity_reference')
  37. ->setName('computed_materials_reference')
  38. ->setLabel(t('Computed Materials References'))
  39. ->setDescription(t('Computed Materials References.'))
  40. // // The Entity Type this field belongs to.
  41. ->setTargetEntityTypeId($entity_type->id())
  42. // // The Entity Type bundle this field belongs to.
  43. ->setTargetBundle($bundle)
  44. ->setSetting('target_type', 'node')
  45. ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
  46. ->setComputed(TRUE)
  47. ->setRevisionable(FALSE)
  48. ->setTranslatable(FALSE)
  49. ->setDisplayConfigurable('view', TRUE)
  50. ->setDisplayOptions('view', [
  51. 'label' => 'hidden',
  52. 'weight' => -5,
  53. ])
  54. ->setClass(\Drupal\materio_home\Plugin\Field\FieldType\ComputedMaterialsReferences::class);
  55. $fields['computed_showrooms_reference'] = BaseFieldDefinition::create('entity_reference')
  56. ->setName('computed_showrooms_reference')
  57. ->setLabel(t('Computed Showrooms References'))
  58. ->setDescription(t('Computed Showrooms References.'))
  59. // // The Entity Type this field belongs to.
  60. ->setTargetEntityTypeId($entity_type->id())
  61. // // The Entity Type bundle this field belongs to.
  62. ->setTargetBundle($bundle)
  63. ->setSetting('target_type', 'taxonomy_term')
  64. ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
  65. ->setComputed(TRUE)
  66. ->setRevisionable(FALSE)
  67. ->setTranslatable(FALSE)
  68. ->setDisplayConfigurable('view', TRUE)
  69. ->setDisplayOptions('view', [
  70. 'label' => 'hidden',
  71. 'weight' => -5,
  72. ])
  73. ->setClass(\Drupal\materio_home\Plugin\Field\FieldType\ComputedShowroomsReferences::class);
  74. $fields['computed_articles_reference'] = BaseFieldDefinition::create('entity_reference')
  75. ->setName('computed_articles_reference')
  76. ->setLabel(t('Computed Articles References'))
  77. ->setDescription(t('Computed Articles References.'))
  78. // // The Entity Type this field belongs to.
  79. ->setTargetEntityTypeId($entity_type->id())
  80. // // The Entity Type bundle this field belongs to.
  81. ->setTargetBundle($bundle)
  82. ->setSetting('target_type', 'node')
  83. ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
  84. ->setComputed(TRUE)
  85. ->setRevisionable(FALSE)
  86. ->setTranslatable(FALSE)
  87. ->setDisplayConfigurable('view', TRUE)
  88. ->setDisplayOptions('view', [
  89. 'label' => 'hidden',
  90. 'weight' => -5,
  91. ])
  92. ->setClass(\Drupal\materio_home\Plugin\Field\FieldType\ComputedArticlesReferences::class);
  93. return $fields;
  94. }
  95. }
  96. // /**
  97. // * implements hook_entity_extra_field_info
  98. // *
  99. // */
  100. // function materio_home_entity_extra_field_info() {
  101. // $extra = [];
  102. // // $extra['node']['frontpage']['form']['computed_materials_reference'] = [
  103. // // 'label' => t('Computed Materials References'),
  104. // // 'description' => t('Computed Materials References'),
  105. // // 'weight' => 10,
  106. // // ];
  107. // // $extra['node']['frontpage']['display']['computed_materials_reference'] = [
  108. // // 'label' => t('Computed Materials References'),
  109. // // 'description' => t('Computed Materials References'),
  110. // // 'weight' => 10,
  111. // // ];
  112. // return $extra;
  113. // }
  114. /**
  115. * Implements hook_install().
  116. */
  117. function materio_home_install() {
  118. $entity_type = \Drupal::service('entity_type.manager')->getDefinition('node');
  119. \Drupal::service('entity.definition_update_manager')->updateEntityType($entity_type);
  120. }
  121. /**
  122. * Implements hook_uninstall().
  123. */
  124. function materio_home_uninstall() {
  125. $entity_type = \Drupal::service('entity_type.manager')->getDefinition('node');
  126. \Drupal::service('entity.definition_update_manager')->updateEntityType($entity_type);
  127. }