<?php

/**
 * @file
 * Install, update and uninstall functions for the webform node module.
 */

/**
 * Implements hook_requirements().
 */
function webform_node_requirements($phase) {
  $requirements = [];
  // Throw error if Webform (webform) content type is already exists which will
  // happen during a D7 to D8 content migration.
  // @see https://www.drupal.org/node/2856599
  if ($phase === 'install') {
    $manager = \Drupal::entityTypeManager();
    if ($manager->hasDefinition('node_type') && ($node_type = $manager->getStorage('node_type')->load('webform'))) {
      $requirements['webform_node'] = [
        'title' => t('Webform Node'),
        'value' => t('%title content type already exists', ['%title' => $node_type->label()]),
        'description' => t('%title content type already exists, please delete the %title content type before installing the Webform node module.', ['%title' => $node_type->label()]),
        'severity' => REQUIREMENT_ERROR,
      ];
    }

  }
  return $requirements;
}
