You are here

function type_style_example_install in Type Style 8

Implements hook_install().

File

modules/type_style_example/type_style_example.install, line 11
Installation routines for the Type Style Example Module.

Code

function type_style_example_install() {
  $colors = [
    '#F44336',
    '#9C27B0',
    '#2196F3',
    '#009688',
    '#8BC34A',
    '#FFEB3B',
  ];
  $icons = [
    'description',
    'face',
    'favorite',
    'thumb_up',
    'visibility',
    'wb_sunny',
  ];

  /** @var \Drupal\node\NodeTypeInterface[] $content_types */
  $content_types = \Drupal::entityTypeManager()
    ->getStorage('node_type')
    ->loadMultiple();
  foreach ($content_types as $type) {
    $type
      ->setThirdPartySetting('type_style', 'color', $colors[array_rand($colors)]);
    $type
      ->setThirdPartySetting('type_style', 'icon', $icons[array_rand($icons)]);
    $type
      ->save();
  }
}