X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fhook%2Fviews_data_alter.twig;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fhook%2Fviews_data_alter.twig;h=03bc80bcdfe92b306bc7e4025d611ed7ed982c21;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/hook/views_data_alter.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/views_data_alter.twig new file mode 100644 index 000000000..03bc80bcd --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/views_data_alter.twig @@ -0,0 +1,54 @@ +/** + * Implements hook_views_data_alter(). + */ +function {{ machine_name }}_views_data_alter(array &$data) { + // Alter the title of the node_field_data:nid field in the Views UI. + $data['node_field_data']['nid']['title'] = t('Node-Nid'); + + // Add an additional field to the users_field_data table. + $data['users_field_data']['example_field'] = [ + 'title' => t('Example field'), + 'help' => t('Some example content that references a user'), + + 'field' => [ + // ID of the field handler to use. + 'id' => 'example_field', + ], + ]; + + // Change the handler of the node title field, presumably to a handler plugin + // you define in your module. Give the ID of this plugin. + $data['node_field_data']['title']['field']['id'] = 'node_title'; + + // Add a relationship that will allow a view whose base table is 'foo' (from + // another module) to have a relationship to 'example_table' (from my module), + // via joining foo.fid to example_table.eid. + // + // This relationship has to be added to the 'foo' Views data, which my module + // does not control, so it must be done in hook_views_data_alter(), not + // hook_views_data(). + // + // In Views data definitions, each field can have only one relationship. So + // rather than adding this relationship directly to the $data['foo']['fid'] + // field entry, which could overwrite an existing relationship, we define + // a dummy field key to handle the relationship. + $data['foo']['unique_dummy_name'] = [ + 'title' => t('Title seen while adding relationship'), + 'help' => t('More information about the relationship'), + + 'relationship' => [ + // Views name of the table being joined to from foo. + 'base' => 'example_table', + // Database field name in example_table for the join. + 'base field' => 'eid', + // Real database field name in foo for the join, to override + // 'unique_dummy_name'. + 'field' => 'fid', + // ID of relationship handler plugin to use. + 'id' => 'standard', + 'label' => t('Default label for relationship'), + ], + ]; + + // Note that the $data array is not returned – it is modified by reference. +}