View source
<?php
define('MERCI_ERROR_TOO_MANY', 1);
define('MERCI_ERROR_CONFLICT', 2);
function merci_views_data_alter(array &$data) {
$data['entityref__roles']['table']['join'] = array(
'node__field_reservable_by' => array(
'left_field' => 'id',
'field' => 'target_id',
'table' => 'user__roles',
),
);
$data['entityref__roles']['roles_entity_ref_target_id'] = array(
'title' => t('Roles'),
'help' => t('Roles that a user belongs to.'),
'argument' => array(
'id' => 'user__roles_rid',
'name table' => 'role',
'name field' => 'name',
'empty field name' => t('No role'),
'zero is null' => TRUE,
'numeric' => TRUE,
),
);
}
function merci_entity_bundle_field_info_alter(&$fields, \Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle) {
foreach ($fields as $name => $field) {
if ($field instanceof \Drupal\field\Entity\FieldConfig && ($settings = $field
->getThirdPartySettings('merci'))) {
foreach ($settings as $constraint => $setting) {
$fields[$name]
->addConstraint($constraint, $setting);
}
}
}
}
function merci_field_widget_third_party_settings_form(\Drupal\Core\Field\WidgetInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $form_mode, $form, \Drupal\Core\Form\FormStateInterface $form_state) {
$element = array();
if ($plugin
->getPluginId() != 'inline_entity_form_complex') {
return $element;
}
$entity_type = $field_definition
->getSetting('target_type');
$entityManager = \Drupal::service('entity.manager');
$entityDefinition = $entityManager
->getDefinition($entity_type);
$element['ief_table_view_mode'] = array(
'#type' => 'container',
);
$field_ui_base_route = $entityDefinition
->get('field_ui_base_route');
if (!$field_ui_base_route) {
$message = \Drupal::translation()
->translate('It is not posible to add fields to the table widget because the %entity_name entity does not have Manage display.', array(
'%entity_name' => $entityDefinition
->getLabel(),
));
$element['ief_table_view_mode']['info'] = array(
'#markup' => $message,
);
return $element;
}
$message = \Drupal::translation()
->translate('It is posible to add fields to the table widget, creatring and activating the view mode %name_view_name. Then go to Manage display of %entity_name entity.', array(
'%name_view_name' => $entity_type . '.' . IEF_TABLE_VIEW_MODE_NAME,
'%entity_name' => $entityDefinition
->getLabel(),
));
$element['ief_table_view_mode']['info'] = array(
'#markup' => $message,
);
return $element;
}