2019-03-25 18:28:17 +01:00
|
|
|
<?php
|
2019-05-23 17:52:46 +02:00
|
|
|
use Drupal\Core\Entity\EntityTypeInterface;
|
|
|
|
use Drupal\Core\Field\BaseFieldDefinition;
|
|
|
|
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
|
|
|
use Drupal\mymodule\Plugin\Field\FieldType\MyFieldComputed;
|
2019-03-25 18:28:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_theme().
|
|
|
|
*/
|
2019-05-23 17:52:46 +02:00
|
|
|
// function materio_home_theme($existing, $type, $theme, $path) {
|
|
|
|
// // @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module
|
|
|
|
//
|
|
|
|
// return array(
|
|
|
|
// 'materio_home' => array(
|
|
|
|
// // 'render element' => '',
|
|
|
|
// 'file' => 'includes/materio_home.inc',
|
|
|
|
// 'variables' => array(
|
|
|
|
// 'frontpage_node' => NULL,
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
// }
|
2019-03-25 18:28:17 +01:00
|
|
|
|
2019-05-23 17:52:46 +02:00
|
|
|
/**
|
|
|
|
* Implement hook_entity_bundle_field_info().
|
|
|
|
*
|
|
|
|
* @param EntityTypeInterface $entity_type
|
|
|
|
* @param $bundle
|
|
|
|
* @param array $base_field_definitions
|
|
|
|
* @return array
|
|
|
|
*/
|
2019-05-24 13:07:50 +02:00
|
|
|
function materio_home_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
|
|
|
|
// function materio_home_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
|
2019-05-23 17:52:46 +02:00
|
|
|
// $fields = array();
|
|
|
|
// if ($entity_type->id() == 'node' && $bundle === 'frontpage') {
|
2019-05-24 13:07:50 +02:00
|
|
|
// \Drupal::logger('materio_home')->notice('bundle: '.$bundle);
|
|
|
|
if ($entity_type->id() == 'node' && $bundle == 'frontpage') {
|
2019-05-23 17:52:46 +02:00
|
|
|
$fields['computed_materials_reference'] = BaseFieldDefinition::create('entity_reference')
|
|
|
|
->setName('computed_materials_reference')
|
|
|
|
->setLabel(t('Computed Materials References'))
|
|
|
|
->setDescription(t('Computed Materials References.'))
|
|
|
|
// // The Entity Type this field belongs to.
|
2019-05-24 13:07:50 +02:00
|
|
|
->setTargetEntityTypeId($entity_type->id())
|
2019-05-23 17:52:46 +02:00
|
|
|
// // The Entity Type bundle this field belongs to.
|
2019-05-24 13:07:50 +02:00
|
|
|
->setTargetBundle($bundle)
|
|
|
|
->setSetting('target_type', 'node')
|
2019-05-23 17:52:46 +02:00
|
|
|
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
|
|
|
|
->setComputed(TRUE)
|
|
|
|
->setRevisionable(FALSE)
|
|
|
|
->setTranslatable(FALSE)
|
|
|
|
->setDisplayConfigurable('view', TRUE)
|
|
|
|
->setDisplayOptions('view', [
|
|
|
|
'label' => 'hidden',
|
|
|
|
'weight' => -5,
|
|
|
|
])
|
|
|
|
->setClass(\Drupal\materio_home\Plugin\Field\FieldType\ComputedMaterialsReferences::class);
|
|
|
|
|
|
|
|
$fields['computed_showrooms_reference'] = BaseFieldDefinition::create('entity_reference')
|
|
|
|
->setName('computed_showrooms_reference')
|
|
|
|
->setLabel(t('Computed Showrooms References'))
|
|
|
|
->setDescription(t('Computed Showrooms References.'))
|
|
|
|
// // The Entity Type this field belongs to.
|
2019-05-24 13:07:50 +02:00
|
|
|
->setTargetEntityTypeId($entity_type->id())
|
2019-05-23 17:52:46 +02:00
|
|
|
// // The Entity Type bundle this field belongs to.
|
2019-05-24 13:07:50 +02:00
|
|
|
->setTargetBundle($bundle)
|
|
|
|
->setSetting('target_type', 'taxonomy_term')
|
2019-05-23 17:52:46 +02:00
|
|
|
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
|
|
|
|
->setComputed(TRUE)
|
|
|
|
->setRevisionable(FALSE)
|
|
|
|
->setTranslatable(FALSE)
|
|
|
|
->setDisplayConfigurable('view', TRUE)
|
|
|
|
->setDisplayOptions('view', [
|
|
|
|
'label' => 'hidden',
|
|
|
|
'weight' => -5,
|
|
|
|
])
|
|
|
|
->setClass(\Drupal\materio_home\Plugin\Field\FieldType\ComputedShowroomsReferences::class);
|
2019-05-24 13:07:50 +02:00
|
|
|
|
|
|
|
$fields['computed_articles_reference'] = BaseFieldDefinition::create('entity_reference')
|
|
|
|
->setName('computed_articles_reference')
|
|
|
|
->setLabel(t('Computed Articles References'))
|
|
|
|
->setDescription(t('Computed Articles 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\materio_home\Plugin\Field\FieldType\ComputedArticlesReferences::class);
|
|
|
|
|
|
|
|
return $fields;
|
2019-05-23 17:52:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// /**
|
|
|
|
// * implements hook_entity_extra_field_info
|
|
|
|
// *
|
|
|
|
// */
|
|
|
|
// function materio_home_entity_extra_field_info() {
|
|
|
|
// $extra = [];
|
|
|
|
// // $extra['node']['frontpage']['form']['computed_materials_reference'] = [
|
|
|
|
// // 'label' => t('Computed Materials References'),
|
|
|
|
// // 'description' => t('Computed Materials References'),
|
|
|
|
// // 'weight' => 10,
|
|
|
|
// // ];
|
|
|
|
// // $extra['node']['frontpage']['display']['computed_materials_reference'] = [
|
|
|
|
// // 'label' => t('Computed Materials References'),
|
|
|
|
// // 'description' => t('Computed Materials References'),
|
|
|
|
// // 'weight' => 10,
|
|
|
|
// // ];
|
|
|
|
// return $extra;
|
|
|
|
// }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_install().
|
|
|
|
*/
|
|
|
|
function materio_home_install() {
|
|
|
|
$entity_type = \Drupal::service('entity_type.manager')->getDefinition('node');
|
|
|
|
\Drupal::service('entity.definition_update_manager')->updateEntityType($entity_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_uninstall().
|
|
|
|
*/
|
|
|
|
function materio_home_uninstall() {
|
|
|
|
$entity_type = \Drupal::service('entity_type.manager')->getDefinition('node');
|
|
|
|
\Drupal::service('entity.definition_update_manager')->updateEntityType($entity_type);
|
2019-03-25 18:28:17 +01:00
|
|
|
}
|