Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/custom_forms / custom_forms.install
Size: Mime:
<?php

use Drupal\Core\Field\BaseFieldDefinition;

/**
 * @file
 * Install, update and uninstall functions for the custom forms module.
 */

function custom_forms_install() {
  $config = \Drupal::config('custom_forms.settings');
  /** @var \Drupal\Core\Config\ConfigFactory $config_factory */
  $config_factory = \Drupal::service('config.factory');
  /** @var \Drupal\Core\Config\Config $editable_config */
  $editable_config = $config_factory->getEditable('custom_forms.settings');

  $editable_config->set('submission_salt', \Drupal\Component\Utility\Crypt::randomBytesBase64(55));
  $editable_config->set('off_screen_field_settings', 'reload');
  $editable_config->save();

  // Set module weight, required to run after other eventsubscribers and hooks.
  module_set_weight('custom_forms', 10);

  $module_handler = \Drupal::moduleHandler();
  // Add Entity usage config settings if the module is enabled.
  if ($module_handler->moduleExists('entity_usage')) {
    /** @var \Drupal\Core\Config\Config $editable_config */
    $editable_config = $config_factory->getEditable('entity_usage.settings');

    $enabled_entities = $editable_config->get('local_task_enabled_entity_types');
    $source_entities = $editable_config->get('track_enabled_source_entity_types');
    $target_entities = $editable_config->get('track_enabled_target_entity_types');
    $delete_warnings = $editable_config->get('delete_warning_message_entity_types');

    // Enable entity usage task (tab) for custom form entities.
    if (!in_array('custom_form', $enabled_entities, FALSE)) {
      $enabled_entities[] = 'custom_form';
    }
    // Mark custom form as being a source entity.
    if (!in_array('custom_form', $source_entities, FALSE)) {
      $source_entities[] = 'custom_form';
    }
    // Mark custom form as being af target entity.
    if (!in_array('custom_form', $target_entities, FALSE)) {
      $target_entities[] = 'custom_form';
    }
    // Enable warning on custom form delete form if it has usages.
    if (!in_array('custom_form', $delete_warnings, FALSE)) {
      $delete_warnings[] = 'custom_form';
    }

    // Set all the config.
    $editable_config->set('local_task_enabled_entity_types', $enabled_entities);
    $editable_config->set('track_enabled_source_entity_types', $source_entities);
    $editable_config->set('track_enabled_target_entity_types', $target_entities);
    $editable_config->set('delete_warning_message_entity_types', $delete_warnings);
    // Save the config.
    $editable_config->save();
  }
}

/**
 * Implements hook_schema().
 *
 * Defines the database tables used by this module.
 *
 * @see hook_schema()
 *
 * @ingroup custom_forms
 */
function custom_forms_schema() {
  $schema['custom_forms__items'] = [
    'description' => 'Stores all the form fields and groups.',
    'fields' => [
      'id' => [
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'The item ID shared between revisions.',
      ],
      'revision' => [
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'Primary Key: Item revision ID.',
      ],
      'form' => [
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'The id of the custom forms form the item is associated with.',
      ],
      'form_revision' => [
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'The id of the revision of the custom forms form the item is associated with.',
      ],
      'created' => [
        'description' => 'The Unix timestamp when the item was created.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'changed' => [
        'description' => 'The Unix timestamp when the item was most recently saved.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'langcode' => [
        'description' => 'The language the field is in.',
        'type' => 'varchar_ascii',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ],
      'type' => [
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'normal',
        'description' => 'The type of the item, can be either "field" or "group".',
      ],
      'plugin' => [
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'normal',
        'description' => 'The plugin ID for the item type being used.',
      ],
      'mapping' => [
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'normal',
        'description' => 'The plugin ID for the item mapping being used. This is only used when "type" is set to "field"',
      ],
      'machine_name' => [
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'normal',
        'description' => 'The machine name for the item.',
      ],
      'settings' => [
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'description' => 'The settings associated with the item.',
      ],
      'states' => [
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'description' => 'The states associated with the item.',
      ],
      'weight' => [
        'description' => 'The sortable weight for this item',
        'type' => 'int',
        'length' => 11,
        'not null' => TRUE,
        'default' => 0,
      ],
      'pid' => [
        'description' => 'The primary id of the parent for this item',
        'type' => 'int',
        'length' => 11,
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => ['id', 'revision', 'langcode'],
    'foreign keys' => [
      'item_form' => [
        'table' => 'custom_forms',
        'columns' => [
          'form' => 'id'
        ],
      ],
      'item_parent' => [
        'table' => 'custom_forms__items',
        'columns' => [
          'pid' => 'id'
        ],
      ],
    ],
  ];

  return $schema;
}

/**
 * Install new mapped data field on submission entity.
 */
function custom_forms_update_8701() {
  $field_storage_definition = BaseFieldDefinition::create('map')
    ->setLabel(t('Mapped data'))
    ->setDescription(t('A serialized array of mapped submission data.'))
    ->setDefaultValue([]);

  \Drupal::entityDefinitionUpdateManager()
    ->installFieldStorageDefinition('mapped_data', 'custom_form_submission', 'custom_form_submission', $field_storage_definition);
}