-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtual_edit_link_field.module
More file actions
48 lines (39 loc) · 1.36 KB
/
virtual_edit_link_field.module
File metadata and controls
48 lines (39 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
// namespace Drupal\virtual_edit_link_field;
/**
* @file
* Contains virtual_edit_link_field.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
/**
* Implements hook_help().
*/
function virtual_edit_link_field_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the virtual_edit_link_field module.
case 'help.page.virtual_edit_link_field':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Creates a virtual edit link field. This contains a virtual link that is useful for linking from a decoupled system or app.') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_entity_base_field_info_alter().
*/
function virtual_edit_link_field_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
if ($entity_type->id() === "node" ) {
$fields['editLink'] = BaseFieldDefinition::create('string')
->setName('Virtual Edit Link Field')
->setLabel(t('Edit Link'))
->setTargetEntityTypeId('node') // required for content translation
->setComputed(TRUE)
->setClass('\Drupal\virtual_edit_link_field\ComputedField')
->setReadOnly(TRUE)
->setRevisionable(TRUE)
->setTranslatable(TRUE);
}
}