Exemplo n.º 1
0
/**
 * This is an example implementation for the hook. Preforms actions when converting a node based on it's type.
 *
 * @param $data
 *   An array containing information about the conversion process. The keys are
 *   - dest_node_type  The destination type of the node
 *   - node  The node object
 *   - Any other information passed by $op = 'options' or $op = 'options validate'
 * @param $op
 *   A string containing the operation which should be executed. These are the possible values
 *   - insert  Operations which should be run when the node is transferred to the new node type.
 *   Usually for transferring and adding new node information into the database.
 *   - delete  Operations which should be run after the node is transferred to the new node type.
 *   Usually for deleting unneeded information from the database after the transfer.
 *   - options  Configuration elements shown on the conversion form. Should return a FAPI array.
 *   - options validate  Validation check on the options elements.
 * @return
 *    Should return a FAPI array only when using the options operation.
 */
function hook_node_convert_change($data, $op)
{
    // All of this is just an example.
    if ($op == 'insert') {
        if ($data['dest_node_type'] == 'book') {
            $book = array();
            $node = $data['node'];
            $book['link_path'] = 'node/' . $node->nid;
            $book['link_title'] = $node->title;
            $book['plid'] = 0;
            $book['menu_name'] = book_menu_name($node->nid);
            $mlid = menu_link_save($book);
            $book['bid'] = $data['hook_options']['bid'];
            if ($book['bid'] == 'self') {
                $book['bid'] = $node->nid;
            }
            $id = db_insert('book')->fields(array('nid' => $node->nid, 'mlid' => $book['mlid'], 'bid' => $book['bid']))->execute();
        }
        if ($data['dest_node_type'] == 'forum') {
            $id = db_insert('forum')->fields(array('tid' => $data['hook_options']['forum'], 'vid' => $data['node']->vid, 'nid' => $data['node']->nid))->execute();
            $id = db_insert('taxonomy_term_node')->fields(array('tid' => $data['hook_options']['forum'], 'vid' => $data['node']->vid, 'nid' => $data['node']->nid))->execute();
        }
    } elseif ($op == 'delete') {
        if ($data['node']->type == 'book') {
            menu_link_delete($data['node']->book['mlid']);
            db_delete('book')->condition('mlid', $data['node']->book['mlid'])->execute();
        }
        if ($data['node']->type == 'forum') {
            db_delete('forum')->condition('nid', $data['node']->nid)->execute();
            db_delete('taxonomy_term_node')->condition('nid', $data['node']->nid)->execute();
        }
    } elseif ($op == 'options') {
        $form = array();
        if ($data['dest_node_type'] == 'book') {
            foreach (book_get_books() as $book) {
                $options[$book['nid']] = $book['title'];
            }
            $options = array('self' => '<' . t('create a new book') . '>') + $options;
            $form['bid'] = array('#type' => 'select', '#title' => t('Book'), '#options' => $options, '#description' => t('Your page will be a part of the selected book.'), '#attributes' => array('class' => 'book-title-select'));
        }
        if ($data['dest_node_type'] == 'forum') {
            $vid = variable_get('forum_nav_vocabulary', '');
            $form['forum'] = taxonomy_form($vid);
            $form['forum']['#weight'] = 7;
            $form['forum']['#required'] = TRUE;
            $form['forum']['#options'][''] = t('- Please choose -');
        }
        return $form;
    } elseif ($op == 'options validate') {
        $form_state = $data['form_state'];
        if ($data['dest_node_type'] == 'forum') {
            $containers = variable_get('forum_containers', array());
            $term = $form_state['values']['hook_options']['forum'];
            if (in_array($term, $containers)) {
                $term = taxonomy_term_load($term);
                form_set_error('hook_options][forum', t('The item %forum is only a container for forums. Please select one of the forums below it.', array('%forum' => $term->name)));
            }
        }
    }
}
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function submit(array $form, array &$form_state)
 {
     menu_link_delete($this->entity->id());
     $t_args = array('%title' => $this->entity->link_title);
     drupal_set_message(t('The menu link %title has been deleted.', $t_args));
     watchdog('menu', 'Deleted menu link %title.', $t_args, WATCHDOG_NOTICE);
     $form_state['redirect_route'] = $this->getCancelUrl();
 }
Exemplo n.º 3
0
function unl_reset_site_submit($form, &$form_state)
{
    $nids = db_select('node', 'n')->fields('n', array('nid'))->execute()->fetchCol();
    node_delete_multiple($nids);
    variable_set('site_frontpage', 'node');
    $mlids = db_select('menu_links', 'm')->fields('m', array('mlid'))->condition('m.menu_name', 'main-menu')->execute()->fetchCol();
    foreach ($mlids as $mlid) {
        menu_link_delete($mlid);
    }
    $home_link = array('link_path' => '<front>', 'link_title' => 'Home', 'menu_name' => 'main-menu', 'module' => 'menu');
    menu_link_save($home_link);
    $fids = db_select('file_managed', 'f')->fields('f', array('fid'))->execute()->fetchCol();
    $files = file_load_multiple($fids);
    foreach ($files as $file) {
        file_delete($file);
    }
    $files_dir = DRUPAL_ROOT . '/' . conf_path() . '/files/';
    $cmd = 'rm -rf ' . $files_dir . '*';
    echo shell_exec($cmd);
    drupal_mkdir('public://styles/');
    variable_set('site_name', 'Site Name');
}
Exemplo n.º 4
0
 /**
  * Deletes custom generated menus
  */
 protected function deleteMenus()
 {
     if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
         foreach (menu_ui_get_menus(FALSE) as $menu => $menu_title) {
             if (strpos($menu, 'devel-') === 0) {
                 Menu::load($menu)->delete();
             }
         }
     }
     // Delete menu links generated by devel.
     $result = db_select('menu_links', 'm')->fields('m', array('mlid'))->condition('m.menu_name', 'devel', '<>')->condition('m.options', '%' . db_like('s:5:"devel";b:1') . '%', 'LIKE')->execute();
     foreach ($result as $link) {
         menu_link_delete($link->mlid);
     }
 }
Exemplo n.º 5
0
 /**
  * Test automatic reparenting of menu links.
  */
 function testMenuLinkReparenting($module = 'menu_test')
 {
     // Check the initial hierarchy.
     $links = $this->createLinkHierarchy($module);
     $expected_hierarchy = array('parent' => FALSE, 'child-1' => 'parent', 'child-1-1' => 'child-1', 'child-1-2' => 'child-1', 'child-2' => 'parent');
     $this->assertMenuLinkParents($links, $expected_hierarchy);
     // Start over, and move child-1 under child-2, and check that all the
     // childs of child-1 have been moved too.
     $links = $this->createLinkHierarchy($module);
     $links['child-1']['plid'] = $links['child-2']['mlid'];
     menu_link_save($links['child-1']);
     $expected_hierarchy = array('parent' => FALSE, 'child-1' => 'child-2', 'child-1-1' => 'child-1', 'child-1-2' => 'child-1', 'child-2' => 'parent');
     $this->assertMenuLinkParents($links, $expected_hierarchy);
     // Start over, and delete child-1, and check that the children of child-1
     // have been reassigned to the parent. menu_link_delete() will cowardly
     // refuse to delete a menu link defined by the system module, so skip the
     // test in that case.
     if ($module != 'system') {
         $links = $this->createLinkHierarchy($module);
         menu_link_delete($links['child-1']['mlid']);
         $expected_hierarchy = array('parent' => FALSE, 'child-1-1' => 'parent', 'child-1-2' => 'parent', 'child-2' => 'parent');
         $this->assertMenuLinkParents($links, $expected_hierarchy);
     }
     // Start over, forcefully delete child-1 from the database, simulating a
     // database crash. Check that the children of child-1 have been reassigned
     // to the parent, going up on the old path hierarchy stored in each of the
     // links.
     $links = $this->createLinkHierarchy($module);
     // Don't do that at home.
     entity_delete_multiple('menu_link', array($links['child-1']['mlid']));
     $expected_hierarchy = array('parent' => FALSE, 'child-1-1' => 'parent', 'child-1-2' => 'parent', 'child-2' => 'parent');
     $this->assertMenuLinkParents($links, $expected_hierarchy);
     // Start over, forcefully delete the parent from the database, simulating a
     // database crash. Check that the children of parent are now top-level.
     $links = $this->createLinkHierarchy($module);
     // Don't do that at home.
     db_delete('menu_links')->condition('mlid', $links['parent']['mlid'])->execute();
     $expected_hierarchy = array('child-1-1' => 'child-1', 'child-1-2' => 'child-1', 'child-2' => FALSE);
     $this->assertMenuLinkParents($links, $expected_hierarchy);
 }
Exemplo n.º 6
0
 public function removeEvent($event_id)
 {
     $resultEvent = db_select($this->tbl_event, 'e')->fields('e', array('bild', 'recurring_event_type'))->condition('EID', $event_id)->execute()->fetchObject();
     db_delete($this->tbl_akteur_events)->condition('EID', $event_id)->execute();
     db_delete($this->tbl_event)->condition('EID', $event_id)->execute();
     db_delete($this->tbl_event_sparte)->condition('hat_EID', $event_id)->execute();
     // remove children-items, if given
     if (!empty($resultEvent->recurring_event_type)) {
         $this->removeEventChildren($event_id);
     }
     // remove profile-image
     $bild = end(explode('/', $resultEvent->bild));
     if (file_exists($this->short_bildpfad . $bild)) {
         @unlink($this->short_bildpfad . $bild);
     }
     menu_link_delete(NULL, 'eventprofil/' . $event_id);
 }
Exemplo n.º 7
0
 public function __removeAkteur($aId)
 {
     $resultAkteur = db_select($this->tbl_akteur, 'a')->fields('a', array('name', 'bild'))->condition('AID', $aId)->execute()->fetchObject();
     $resultEvents = db_select($this->tbl_akteur_events, 'ae')->fields('ae')->condition('AID', $aId)->execute()->fetchAll();
     foreach ($resultEvents as $event) {
         db_delete($this->tbl_event)->condition('EID', $event->EID)->execute();
     }
     db_delete($this->tbl_akteur_events)->condition('AID', $aId)->execute();
     db_delete($this->tbl_hat_user)->condition('hat_AID', $aId)->execute();
     db_delete($this->tbl_akteur)->condition('AID', $aId)->execute();
     db_delete($this->tbl_hat_sparte)->condition('hat_AID', $aId)->execute();
     // Remove profile-image (if possible)
     $bild = end(explode('/', $resultAkteur->bild));
     if (file_exists($this->short_bildpfad . $bild)) {
         unlink($this->short_bildpfad . $bild);
     }
     menu_link_delete(NULL, 'akteurprofil/' . $aId);
 }
 /**
  * {@inheritdoc}
  */
 public function delete($itemId)
 {
     menu_link_delete($itemId);
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function deleteExistingObject(NodeInterface $node, Context $context, $dirtyAllowed = false)
 {
     if ($mlid = $this->findMenuItemId($node, $context)) {
         menu_link_delete($mlid);
     }
 }
Exemplo n.º 10
0
 /**
  * Reinitialize some Community environment settings.
  *
  * @AfterFeature @cleanCommunityEnvironment
  */
 public static function cleanCommunityEnvironment()
 {
     // Delete 'community' node type.
     _node_types_build(TRUE);
     node_type_delete('community');
     field_purge_batch(1);
     // Delete community's variables.
     $feature = features_load_feature('nexteuropa_communities');
     if (isset($feature->info['features']['variable'])) {
         foreach ($feature->info['features']['variable'] as $varname) {
             variable_del($varname);
         }
     }
     // Delete community's menu_links.
     if (isset($feature->info['features']['menu_links'])) {
         foreach ($feature->info['features']['menu_links'] as $menulinks) {
             menu_link_delete(NULL, $menulinks);
         }
     }
     // Delete community's menu_custom.
     if (isset($feature->info['features']['menu_custom'])) {
         foreach ($feature->info['features']['menu_custom'] as $menucustom) {
             $menu = menu_load($menucustom);
             menu_delete($menu);
         }
     }
     drupal_flush_all_caches();
 }