You are here

function message_digest_update_8101 in Message Digest 8

Converts hard-coded intervals to config entities.

File

./message_digest.install, line 164
Install and update hooks for the Message Digest module.

Code

function message_digest_update_8101() {

  // Install the new entity type.
  $config_entity = new ConfigEntityType([
    'id' => 'message_digest_interval',
    'label' => new TranslatableMarkup('Message digest interval'),
    'config_prefix' => 'interval',
    'admin_permission' => 'administer message digest',
    'entity_keys' => [
      'id' => 'id',
      'label' => 'label',
      'langcode' => 'langcode',
    ],
    'config_export' => [
      'id',
      'label',
      'interval',
      'langcode',
      'description',
    ],
    'handlers' => [
      'form' => [
        'add' => MessageDigestIntervalForm::class,
        'edit' => MessageDigestIntervalForm::class,
      ],
      'list_builder' => MessageDigestIntervalListBuilder::class,
    ],
    'links' => [
      'add-form' => '/admin/config/message/message-digest/interval/add',
      'edit-form' => '/admin/config/message/message-digest/manage/{message_digest_interval}',
    ],
  ]);
  \Drupal::entityDefinitionUpdateManager()
    ->installEntityType($config_entity);

  // Installs the message digest daily and weekly intervals.
  $config = MessageDigestInterval::create([
    'id' => 'daily',
    'label' => 'Daily',
    'description' => 'Sends messages in 1 day intervals.',
    'interval' => '1 day',
    'langcode' => 'en',
    'status' => TRUE,
    'dependencies' => [],
  ]);
  $config
    ->save();
  $config = MessageDigestInterval::create([
    'id' => 'weekly',
    'label' => 'Weekly',
    'description' => 'Sends messages in 1 week intervals.',
    'interval' => '1 week',
    'langcode' => 'en',
    'status' => TRUE,
    'dependencies' => [],
  ]);
  $config
    ->save();
}