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/customeredit / customeredit.install
Size: Mime:
<?php
use Drupal\customeredit\CustomerTextsBuilder;

/**
 * Implements hook_schema().
 */
function customeredit_schema() {
  $schema['customeredit'] = [
    'description' => 'Customer editable data storage.',
    'fields' => [
      'machine_name' => [
        'description' => 'Machine name id for data.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ],
      'type' => [
        'description' => 'The form type to use for editing',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
      ],
      'translatable' => [
        'description' => 'Whether the text is translatable or not.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => FALSE,
      ],
      'location_url' => [
        'description' => 'URL of the page where the text is located',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ],
      'location_selector' => [
        'description' => 'The CSS selector of the element where the text is located',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ],
      'token_types' => [
        'description' => 'The types of tokens available on the text',
        'type' => 'varchar',
        'length' => 2048,
        'not null' => TRUE,
      ],
      'clear_cache' => [
        'description' => 'Whether to clear all cache if text is changed',
        'type' => 'int',
        'size' => 'tiny',
        'default' => 0,
      ],
    ],
    'primary key' => ['machine_name'],
  ];

  $schema['customeredit_labels'] = [
    'description' => 'Customer editable labels storage.',
    'fields' => [
      'machine_name' => [
        'description' => 'Machine name id for data.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ],
      'langcode' => [
        'description' => 'The language of this titles, description, etc.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
      ],
      'title' => [
        'description' => 'Title for the form element',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ],
      'description' => [
        'description' => 'Description for the form element',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ],
      'category' => [
        'description' => 'Category for the administration interface',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ],
      'subcategory' => [
        'description' => 'Subcategory for the administration interface',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'initial' => '',
      ],
    ],
    'indexes' => [
      'category' => ['category'],
    ],
    'primary key' => ['machine_name', 'langcode'],
  ];

  $schema['customeredit_texts'] = [
    'description' => 'Customer editable texts storage.',
    'fields' => [
      'machine_name' => [
        'description' => 'Machine name id for text.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ],
      'langcode' => [
        'description' => 'The language of this data',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => 'en',
      ],
      'data' => [
        'description' => 'Editable data.',
        'type' => 'text',
        'not null' => TRUE,
      ],
    ],
    'primary key' => ['machine_name', 'langcode'],
  ];

  return $schema;
}

/**
 * Implements hook_install().
 */
function customeredit_install() {
  /** @var CustomerTextsBuilder $builder */
  $builder = \Drupal::service('customeredit.texts.builder');
  $builder->rebuild();
}

/**
 * Update the schema
 */
function customeredit_update_8002() {
  $database = Drupal::database();
  $schema = $database->schema();
  $spec = [
    'description' => 'Whether to clear all cache if text is changed',
    'type' => 'int',
    'size' => 'tiny',
    'default' => 0,
  ];
  $schema->addField('customeredit_texts', 'clear_cache', $spec);
}

/**
 * Update the schema
 */
function customeredit_update_8003() {
  $database = Drupal::database();
  $schema = $database->schema();
  $spec = [
    'description' => 'The types of tokens available on the text',
    'type' => 'varchar',
    'length' => 2048,
    'not null' => TRUE,
    'default' => ''
  ];
  $schema->addField('customeredit_texts', 'token_types', $spec);
}

/**
 * Update the schema
 */
function customeredit_update_8004() {
  $schemas = customeredit_schema();
  $database = Drupal::database();
  $schema = $database->schema();

  $schema->dropField('customeredit_texts', 'title');
  $schema->dropField('customeredit_texts', 'description');
  $schema->dropField('customeredit_texts', 'category');
  $schema->dropField('customeredit_texts', 'type');
  $schema->dropField('customeredit_texts', 'translatable');
  $schema->dropField('customeredit_texts', 'token_types');
  $schema->dropField('customeredit_texts', 'clear_cache');
  $schema->addField('customeredit_texts', 'langcode', $schemas['customeredit_texts']['fields']['langcode']);
  $schema->dropPrimaryKey('customeredit_texts');
  $schema->addPrimaryKey('customeredit_texts', $schemas['customeredit_texts']['primary key']);
  $database->update('customeredit_texts')->fields(['langcode' => 'en'])->execute();

  $schema->createTable('customeredit', $schemas['customeredit']);

  $schema->createTable('customeredit_labels', $schemas['customeredit_labels']);
}

/**
 * Update the schema
 */
function customeredit_update_8005() {
  $schemas = customeredit_schema();
  $database = Drupal::database();
  $schema = $database->schema();

  $schema->addField('customeredit', 'location_url', $schemas['customeredit']['fields']['location_url']);
  $schema->addField('customeredit', 'location_selector', $schemas['customeredit']['fields']['location_selector']);
}

/**
 * Update the schema
 */
function customeredit_update_8006() {
  $schemas = customeredit_schema();
  $database = Drupal::database();
  $schema = $database->schema();

  $schema->addField('customeredit_labels', 'subcategory', $schemas['customeredit_labels']['fields']['subcategory']);
}