You are here

function we_megamenu_entity_presave in Drupal Mega Menu 8.x

Same name and namespace in other branches
  1. 8 we_megamenu.module \we_megamenu_entity_presave()

Implements hook_entity_presave().

Reset menu to default status when origin menu changed.

File

./we_megamenu.module, line 747
Drupal 8 Mega Menu Module.

Code

function we_megamenu_entity_presave(EntityInterface $entity) {
  if (method_exists($entity, 'getTypedData') && method_exists($entity, 'getEntityTypeId')) {
    $data = $entity
      ->getTypedData();
    $data = $data
      ->toArray();
    $entity_type = $entity
      ->getEntityTypeId();
    switch ($entity_type) {
      case 'menu':
        $menu_name = $data['id'];
        $config = \Drupal::config('system.theme');
        $theme_name = $config
          ->get('default');
        $tmp_col_content = new stdClass();
        $tmp_col_content->mlid = '';
        $tmp_col_content->type = 'we-mega-menu-li';
        $tmp_col_content->item_config = new stdClass();
        $tmp_col_cfg = new stdClass();
        $tmp_col_cfg->hidewhencollapse = '';
        $tmp_col_cfg->type = 'we-mega-menu-col';
        $tmp_col_cfg->width = 12;
        $tmp_col_cfg->block = '';
        $tmp_col_cfg->class = '';
        $tmp_col_cfg->block_title = 0;
        $child_item = [
          'col_content' => $tmp_col_content,
          'col_cfg' => $tmp_col_cfg,
        ];
        $menu_config = WeMegaMenuBuilder::loadConfig($menu_name, $theme_name);
        if (!empty($menu_config)) {
          $menu_config->menu_update_flag = 1;
          WeMegaMenuBuilder::saveConfig($menu_name, $theme_name, json_encode($menu_config));
        }
        break;
      case 'menu_link_content':
        break;
    }
  }
}