materio_home.module 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. if ($entity_type->id() == 'node') {
  35. $fields['computed_materials_reference'] = BaseFieldDefinition::create('entity_reference')
  36. ->setName('computed_materials_reference')
  37. ->setLabel(t('Computed Materials References'))
  38. ->setDescription(t('Computed Materials References.'))
  39. // // The Entity Type this field belongs to.
  40. ->setSetting('target_type', 'node')
  41. // // The Entity Type bundle this field belongs to.
  42. ->setTargetBundle('frontpage')
  43. ->setTargetEntityTypeId('node')
  44. ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
  45. ->setComputed(TRUE)
  46. ->setRevisionable(FALSE)
  47. ->setTranslatable(FALSE)
  48. ->setDisplayConfigurable('view', TRUE)
  49. ->setDisplayOptions('view', [
  50. 'label' => 'hidden',
  51. 'weight' => -5,
  52. ])
  53. ->setClass(\Drupal\materio_home\Plugin\Field\FieldType\ComputedMaterialsReferences::class);
  54. $fields['computed_showrooms_reference'] = BaseFieldDefinition::create('entity_reference')
  55. ->setName('computed_showrooms_reference')
  56. ->setLabel(t('Computed Showrooms References'))
  57. ->setDescription(t('Computed Showrooms References.'))
  58. ->setSetting('target_type', 'taxonomy_term')
  59. // // The Entity Type this field belongs to.
  60. ->setTargetEntityTypeId('node')
  61. // // The Entity Type bundle this field belongs to.
  62. ->setTargetBundle('frontpage')
  63. ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
  64. ->setComputed(TRUE)
  65. ->setRevisionable(FALSE)
  66. ->setTranslatable(FALSE)
  67. ->setDisplayConfigurable('view', TRUE)
  68. ->setDisplayOptions('view', [
  69. 'label' => 'hidden',
  70. 'weight' => -5,
  71. ])
  72. ->setClass(\Drupal\materio_home\Plugin\Field\FieldType\ComputedShowroomsReferences::class);
  73. }
  74. return $fields;
  75. }
  76. // /**
  77. // * implements hook_entity_extra_field_info
  78. // *
  79. // */
  80. // function materio_home_entity_extra_field_info() {
  81. // $extra = [];
  82. // // $extra['node']['frontpage']['form']['computed_materials_reference'] = [
  83. // // 'label' => t('Computed Materials References'),
  84. // // 'description' => t('Computed Materials References'),
  85. // // 'weight' => 10,
  86. // // ];
  87. // // $extra['node']['frontpage']['display']['computed_materials_reference'] = [
  88. // // 'label' => t('Computed Materials References'),
  89. // // 'description' => t('Computed Materials References'),
  90. // // 'weight' => 10,
  91. // // ];
  92. // return $extra;
  93. // }
  94. /**
  95. * Implements hook_install().
  96. */
  97. function materio_home_install() {
  98. $entity_type = \Drupal::service('entity_type.manager')->getDefinition('node');
  99. \Drupal::service('entity.definition_update_manager')->updateEntityType($entity_type);
  100. }
  101. /**
  102. * Implements hook_uninstall().
  103. */
  104. function materio_home_uninstall() {
  105. $entity_type = \Drupal::service('entity_type.manager')->getDefinition('node');
  106. \Drupal::service('entity.definition_update_manager')->updateEntityType($entity_type);
  107. }