You are here

lingotek_cohesion_test.install in Lingotek Translation 3.4.x

Install, update and uninstall functions for the lingotek_cohesion_test module.

File

tests/modules/lingotek_cohesion_test/lingotek_cohesion_test.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the lingotek_cohesion_test module.
 */
use Drupal\Component\Serialization\Json;

/**
 * Implements hook_install().
 */
function lingotek_cohesion_test_install() {
  _lingotek_cohesion_test_init_js_files();
  _lingotek_cohesion_test_init_form_components();
}

/**
 * Some JS are required, but those are generated by the service on import.
 *
 * See \Drupal\cohesion\Services\LocalFilesManager and "drush cohesion:import".
 */
function _lingotek_cohesion_test_init_js_files() {
  \Drupal::service('file_system')
    ->mkdir(COHESION_JS_PATH, 0777, FALSE);
  \Drupal::service('file_system')
    ->mkdir(COHESION_JS_PATH . '/dx8', 0777, FALSE);
  file_put_contents('public://cohesion/scripts/dx8/vendor.js', '{}');
  file_put_contents('public://cohesion/scripts/dx8/scripts.js', '{}');
  file_put_contents('public://cohesion/scripts/dx8/app.js', '{}');
}
function _lingotek_cohesion_test_init_form_components() {
  $formComponentsJson = <<<'JSON'
{"form-accordion":{"type":"form-container","uid":"form-accordion","title":"Group accordion","parentIndex":"form-layout","status":{"collapsed":false},"options":{"formBuilder":true},"model":{"settings":{"type":"cohAccordion","title":"Group accordion","htmlClass":"coh-accordion-panel-body--dark","isOpen":true}},"children":[]},"form-checkbox-toggle":{"type":"form-field","uid":"form-checkbox-toggle","title":"Toggle","parentIndex":"form-fields","translate":true,"status":{"collapsed":false},"model":{"settings":{"type":"checkboxToggle","title":"Toggle","schema":{"type":"string"}}}},"form-colorpicker":{"type":"form-field","uid":"form-colorpicker","title":"Color picker","parentIndex":"form-fields","status":{"collapsed":false},"model":{"settings":{"type":"cohColourPickerOpener","title":"Color picker","colourPickerOptions":{"flat":true},"schema":{"type":"object"}}}},"form-entity-browser":{"type":"form-field","uid":"form-entity-browser","title":"Entity browser","parentIndex":"form-fields","status":{"collapsed":false},"model":{"settings":{"title":"Entity browser","type":"cohEntityBrowser","showConfig":false,"hideRowHeading":true,"schema":{"type":"object"}}}},"form-entity-reference":{"type":"form-field","uid":"form-entity-reference","title":"Entity reference","parentIndex":"form-fields","selected":false,"status":{"collapsed":false,"isopen":false},"model":{"settings":{"title":"Entity reference","type":"cohEntityPicker","schema":{"type":"object"}}}},"form-field-repeater":{"type":"form-field-container","uid":"form-field-repeater","title":"Field repeater","parentIndex":"form-layout","selected":false,"status":{"collapsed":false,"isopen":false},"options":{"formBuilder":true},"model":{"settings":{"type":"cohArray","title":"Field repeater","componentField":true,"noTitle":true,"htmlClass":"coh-array--field-repeater","disableScrollbar":true,"addText":"Add","key":"field-repeater","sortable":true,"sortableOptions":{"axis":"y","handle":true},"schema":{"type":"array"}}},"children":[]},"form-fontpicker":{"type":"form-field","uid":"form-fontpicker","title":"Font picker","parentIndex":"form-fields","status":{"collapsed":false},"model":{"settings":{"type":"cohSelect","title":"Font picker","selectType":"existing","valueProperty":"stack.variable","labelProperty":"stack.name","selectModel":["styles","font_and_color","font-and-color","font-family.value"],"schema":{"type":"string"}}}},"form-google-map-marker":{"type":"form-field","uid":"form-google-map-marker","title":"Google map marker","parentIndex":"form-fields","status":{"collapsed":false},"model":{"settings":{"type":"cohGoogleMarker","title":"Google map marker","schema":{"type":"string"}}}},"form-helptext":{"type":"form-help","uid":"form-helptext","title":"Help text","parentIndex":"form-help","status":{"collapsed":false},"model":{"settings":{"title":"Help text","type":"cohHelpText","options":{"showClose":false,"helpType":"coh-help-text--help"}}}},"form-iconpicker":{"type":"form-field","uid":"form-iconpicker","title":"Icon picker","parentIndex":"form-fields","status":{"collapsed":false},"model":{"settings":{"type":"cohIconPickerOpener","title":"Icon picker","menuPicker":true,"schema":{"type":"object"}}}},"form-image":{"type":"form-field","uid":"form-image","title":"Image uploader","parentIndex":"form-fields","status":{"collapsed":false},"model":{"settings":{"type":"cohFileBrowser","options":{"buttonText":"Select image","imageUploader":false,"allowedDescription":"Allowed: png, gif, jpg, jpeg \nMax file size: 2MB","removeLabel":"Remove"},"title":"Image uploader","isStyle":true,"defaultActive":true,"schema":{"type":"string"}}}},"form-input":{"type":"form-field","uid":"form-input","title":"Input","parentIndex":"form-fields","translate":true,"status":{"collapsed":false},"model":{"settings":{"title":"Input","schema":{"type":"string"}}}},"form-input-hidden":{"type":"form-field","uid":"form-input-hidden","title":"Hidden input","parentIndex":"form-fields","translate":true,"status":{"collapsed":false},"model":{"settings":{"type":"cohHidden","title":"Hidden input","schema":{"type":"string"}}}},"form-link":{"type":"form-field","uid":"form-link","title":"Link","parentIndex":"form-fields","translate":true,"status":{"collapsed":false},"model":{"settings":{"isStyle":true,"type":"cohTypeahead","key":"linkToPage","title":"Link to page","placeholder":"Type page name","labelProperty":"name","valueProperty":"id","typeaheadEditable":true,"endpoint":"\/cohesionapi\/link-autocomplete?q=","schema":{"type":"string"}}}},"form-range-slider":{"type":"form-field","uid":"form-range-slider","title":"Range slider","parentIndex":"form-fields","status":{"collapsed":false},"model":{"settings":{"type":"cohRange","title":"Range slider","min":0,"max":10,"step":1,"schema":{"type":"number"}}}},"form-section":{"type":"form-container","uid":"form-section","title":"Field group","parentIndex":"form-layout","status":{"collapsed":false},"options":{"formBuilder":true},"model":{"settings":{"type":"cohSection","title":"Field group","hideRowHeading":0,"removePadding":0,"columnCount":"coh-component-field-group-1-col","breakpointIcon":"","breakpoints":false,"propertiesMenu":false,"disableScrollbar":true,"disableEllipsisMenu":true,"isOpen":true}},"children":[]},"form-select":{"type":"form-field","uid":"form-select","title":"Select","parentIndex":"form-fields","translate":false,"status":{"collapsed":false},"model":{"settings":{"type":"cohSelect","title":"Select","selectType":"custom","schema":{"type":"string"}}}},"form-tab-container":{"type":"form-container","uid":"form-tab-container","title":"Tab container","parentIndex":"form-layout","status":{"collapsed":false},"options":{"formBuilder":true},"model":{"settings":{"type":"cohTabContainer","title":"Tab container","responsiveMode":true}},"children":[]},"form-tab-item":{"type":"form-container","uid":"form-tab-item","title":"Tab item","parentIndex":"form-layout","status":{"collapsed":false},"options":{"formBuilder":true},"model":{"settings":{"type":"cohTabItem","title":"Tab item","breakpointIcon":""}},"children":[]},"form-textarea":{"type":"form-field","uid":"form-textarea","title":"Plain text area","parentIndex":"form-fields","translate":true,"status":{"collapsed":false},"model":{"settings":{"type":"cohTextarea","title":"Plain text area","schema":{"type":"string"}}}},"form-video-embed":{"type":"form-field","uid":"form-video-embed","title":"Video","parentIndex":"form-fields","status":{"collapsed":false},"model":{"settings":{"type":"cohMediaEmbed","options":{"noPlugin":true},"title":"Video URL","schema":{"type":"string"}}}},"form-wysiwyg":{"type":"form-field","uid":"form-wysiwyg","title":"WYSIWYG","parentIndex":"form-fields","translate":true,"status":{"collapsed":false},"model":{"settings":{"type":"cohWysiwyg","title":"WYSIWYG","schema":{"type":"object"}}}},"form-youtube-embed":{"type":"form-field","uid":"form-youtube-embed","title":"Youtube URL","parentIndex":"form-fields","status":{"collapsed":false},"model":{"settings":{"type":"cohYoutubeEmbed","title":"Youtube URL","schema":{"type":"string","cohValidate":["youTubeUrl"]}}}}}
JSON;
  $formComponents = Json::decode($formComponentsJson);
  $keyValueStore = \Drupal::keyValue('cohesion.assets.form_elements');
  $keyValueStore
    ->setMultiple($formComponents);
}

Functions

Namesort descending Description
lingotek_cohesion_test_install Implements hook_install().
_lingotek_cohesion_test_init_form_components
_lingotek_cohesion_test_init_js_files Some JS are required, but those are generated by the service on import.