Skip to content

Commit c4279cc

Browse files
committed
updated install script to add visibility field
1 parent 787ca84 commit c4279cc

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

.github/workflows/playwright.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ jobs:
3232
run: |
3333
URL=$(ddev describe -j | jq -r .raw.services.web.https_url)
3434
echo "BASE_URL=$URL" >> $GITHUB_ENV
35-
- name: Run drush command
36-
run: ddev drush config-set core.entity_form_display.node.page.default content.field_visibility.type options_select -y
3735
- name: Run Playwright tests
3836
run: npx playwright test
3937
env:

ubc_cwl_auth.install

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
use Drupal\taxonomy\Entity\Term;
44
use Drupal\taxonomy\Entity\Vocabulary;
5+
use Drupal\field\Entity\FieldStorageConfig;
6+
use Drupal\field\Entity\FieldConfig;
7+
use Drupal\Core\Entity\Entity\EntityFormDisplay;
8+
use Drupal\Core\Entity\Entity\EntityViewDisplay;
59

610
/**
711
* Implements hook_install().
812
*/
913
function ubc_cwl_auth_install() {
1014
ubc_cwl_auth_createCwlRole();
1115
ubc_cwl_auth_createVisibilityTaxonomy();
16+
ubc_cwl_auth_createVisibilityField();
1217
}
1318

1419
function ubc_cwl_auth_createCwlRole() {
@@ -92,3 +97,67 @@ function ubc_cwl_auth_createVisibilityTaxonomy() {
9297

9398
}
9499

100+
function ubc_cwl_auth_createVisibilityField() {
101+
$entity_type = 'node';
102+
$bundle = 'page';
103+
$field_name = 'field_visibility';
104+
$vocabulary = 'visibility';
105+
106+
if (!FieldStorageConfig::loadByName($entity_type, $field_name)) {
107+
FieldStorageConfig::create([
108+
'field_name' => $field_name,
109+
'entity_type' => $entity_type,
110+
'type' => 'entity_reference',
111+
'cardinality' => 1,
112+
'settings' => [
113+
'target_type' => 'taxonomy_term',
114+
],
115+
'translatable' => TRUE,
116+
])->save();
117+
\Drupal::logger('field_setup')->info('Created field storage for @field.', ['@field' => $field_name]);
118+
}
119+
120+
if (!FieldConfig::loadByName($entity_type, $bundle, $field_name)) {
121+
FieldConfig::create([
122+
'entity_type' => $entity_type,
123+
'bundle' => $bundle,
124+
'field_name' => $field_name,
125+
'label' => 'Visibility',
126+
'description' => 'Select visibility level for this page.',
127+
'required' => TRUE,
128+
'settings' => [
129+
'handler' => 'default:taxonomy_term',
130+
'handler_settings' => [
131+
'target_bundles' => [
132+
$vocabulary => $vocabulary,
133+
],
134+
'auto_create' => FALSE,
135+
],
136+
],
137+
'required' => FALSE,
138+
])->save();
139+
\Drupal::logger('field_setup')->info('Created field instance for @field on @bundle.', ['@field' => $field_name, '@bundle' => $bundle]);
140+
}
141+
142+
$form_display = \Drupal::entityTypeManager()->getStorage('entity_form_display')->load("{$entity_type}.{$bundle}.default");
143+
if ($form_display) {
144+
$form_display->setComponent($field_name, [
145+
'type' => 'options_select',
146+
'weight' => 122,
147+
'region' => 'content',
148+
])->save();
149+
}
150+
151+
$view_display = \Drupal::entityTypeManager()->getStorage('entity_view_display')->load("{$entity_type}.{$bundle}.default");
152+
if ($view_display) {
153+
$view_display->setComponent($field_name, [
154+
'type' => 'entity_reference_label',
155+
'label' => 'above',
156+
])->save();
157+
}
158+
159+
\Drupal::logger('field_setup')->info('Field @field successfully created for content type @bundle.', [
160+
'@field' => $field_name,
161+
'@bundle' => $bundle,
162+
]);
163+
}

0 commit comments

Comments
 (0)