/**
  * Overrides EntityInlineEntityFormController::entityForm().
  *
  * Copied from fieldable_panels_panes_entity_edit_form().
  */
 public function entityForm($entity_form, &$form_state)
 {
     // Make the other form items dependent upon it.
     ctools_include('dependent');
     ctools_add_js('dependent');
     $entity = $entity_form['#entity'];
     $entity_type = 'fieldable_panels_pane';
     list(, , $bundle) = entity_extract_ids($entity_type, $entity);
     // Map these properties for entity translations.
     $entity_form['#entity_type'] = array('#type' => 'value', '#value' => $entity->bundle);
     $form_state['fieldable_panels_pane'] = $entity_form['#entity'];
     $entity_form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#default_value' => $entity->title, '#weight' => -10);
     $entity_form['language'] = array('#type' => 'value', '#value' => $entity->language);
     $entity_form['link'] = array('#weight' => -10);
     $entity_form['link']['link'] = array('#title' => t('Make title a link'), '#type' => 'checkbox', '#default_value' => $entity->link, '#description' => t('Check here to make the title link to another page.'), '#id' => 'edit-link');
     $entity_form['link']['path'] = array('#type' => 'textfield', '#title' => t('Path'), '#description' => t('The path for this link. This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page.', array('%front' => '<front>', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org')), '#dependency' => array('edit-link' => array(1)), '#default_value' => $entity->path);
     $entity_form['reusable'] = array('#weight' => 10);
     $entity_form['revision'] = array('#weight' => 11);
     if (empty($entity->fpid)) {
         $entity_form['revision']['#access'] = FALSE;
     }
     $entity_form['reusable']['reusable'] = array('#type' => 'checkbox', '#title' => t('Make this entity reusable'), '#default_value' => $entity->reusable, '#id' => 'edit-reusable');
     $entity_form['reusable']['category'] = array('#type' => 'textfield', '#title' => t('Category'), '#description' => t('The category this content will appear in the "Add content" modal. If left blank the category will be "Miscellaneous".'), '#dependency' => array('edit-reusable' => array(1)), '#default_value' => $entity->category);
     $entity_form['reusable']['admin_title'] = array('#type' => 'textfield', '#title' => t('Administrative title'), '#description' => t('The name this content will appear in the "Add content" modal.'), '#dependency' => array('edit-reusable' => array(1)), '#default_value' => $entity->admin_title);
     $entity_form['reusable']['admin_description'] = array('#type' => 'textarea', '#title' => t('Administrative description'), '#description' => t('A description of what this content is, does or is for, for administrative use.'), '#dependency' => array('edit-reusable' => array(1)), '#default_value' => $entity->admin_description);
     $entity_form['revision']['revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => 1, '#id' => 'edit-revision');
     if (!user_access('administer fieldable panels panes') || empty($entity->fpid) || $entity->vid != $entity->current_vid) {
         $form['revision']['revision']['#disabled'] = TRUE;
         $form['revision']['revision']['#value'] = TRUE;
     }
     $entity_form['revision']['log'] = array('#type' => 'textarea', '#title' => t('Log message'), '#description' => t('Provide an explanation of the changes you are making. This will help other authors understand your motivations.'), '#dependency' => array('edit-revision' => array(1)), '#default_value' => '');
     $langcode = entity_language('fieldable_panels_pane', $entity);
     field_attach_form('fieldable_panels_pane', $entity, $entity_form, $form_state, $langcode);
     // _field_extra_fields_pre_render() doesn't execute properly, so manually
     // set the weights.
     $extra_fields = field_info_extra_fields($entity_type, $bundle, 'form');
     foreach ($extra_fields as $name => $settings) {
         if (isset($entity_form[$name])) {
             $entity_form[$name]['#weight'] = $settings['weight'];
         }
     }
     return $entity_form;
 }
Example #2
0
 /**
  * Returns the entity language.
  *
  * @return string
  *   The entity language.
  */
 public function getEntityLanguage()
 {
     if (field_is_translatable($this->entityType, $this->fieldInfo)) {
         return entity_language($this->entityType, $this->entity);
     }
     return LANGUAGE_NONE;
 }
Example #3
0
/**
 * Implements template_preprocess_page
 *
 * Available vars:
 *
 *  
 */
function medtravel_preprocess_page(&$variables)
{
    // loads entity data
    $url_params = current_path();
    $params = explode('/', $url_params);
    // if belongs to micro entity type
    if ($params[0] == 'micro') {
        $id = $params[1];
        $entity = entity_load('micro', array($id));
        if (!empty($entity)) {
            $variables['entity_not_found'] = false;
            $entity = $entity[$id];
            // get the current language
            $lang = entity_language('micro', $entity);
            $variables['micro'] = $entity;
            // builds variables
            $header_img = file_load($entity->field_header_img['und'][0]['fid']);
            $body_img = file_load($entity->field_body_img['und'][0]['fid']);
            // field with multiple values
            $variables['map'] = $entity->field_map['und'];
            $variables['gallery'] = $entity->field_footer_gallery['und'];
            $variables['footerLinks'] = $entity->field_footer_link[$lang];
            $variables['footerAttachments'] = $entity->field_footer_attachment[$lang];
            $variables['listItems'] = $entity->field_list_items[$lang];
            $variables['mid'] = $entity->mid;
            $variables['name'] = $entity->name;
            $variables['category'] = $entity->category;
            $variables['likes'] = $entity->likes;
            $variables['num_likes'] = $entity->num_likes;
            $variables['social_fb'] = $entity->social_fb;
            $variables['social_tw'] = $entity->social_tw;
            $variables['share'] = $entity->share;
            $variables['bookmarks'] = $entity->bookmarks;
            $variables['title_links'] = $entity->title_links;
            $variables['title_attachments'] = $entity->title_attachments;
            $variables['map_title'] = $entity->map_title;
            $variables['related'] = module_invoke('related', 'block_view', 'related');
        } else {
            $variables['entity_not_found'] = true;
        }
    }
    if (drupal_is_front_page()) {
        //get language
        global $language;
        $langcode = $language->language;
        if ($langcode == 'es') {
            $langcode = '';
        }
        if ($langcode == 'en') {
            $langcode = '_en';
        }
        $variables['langcode'] = $langcode;
        //get data
        $data = get_home_data();
        $data = $data[0];
        //render home blocks
        $variables['home_block'] = module_invoke('home', 'block_view', 'home_block');
        $video = file_load($data['video']);
        if (!empty($video)) {
            $variables['home_video'] = file_create_url($video->uri);
        }
        $video_img = file_load($data['video_img']);
        if (!empty($video_img)) {
            $variables['home_video_img'] = file_create_url($video_img->uri);
        }
        $variables['home_title'] = $data['title' . $langcode];
        $variables['home_description'] = $data['description' . $langcode];
        $variables['home_que_visitar'] = $data['tab_que_visitar'];
        $variables['home_donde_quedarme'] = $data['tab_donde_quedarme'];
        $variables['home_como_moverme'] = $data['tab_como_moverme'];
        // home tabs
        $criteria = array('lugares', 'transporte', 'hospedaje');
        foreach ($criteria as $crit) {
            $options = array();
            // if is transporte take data from micro table
            if ($crit == 'transporte') {
                $children = query_tab_special_class($criteria);
                foreach ($children as $child) {
                    $options[$child->mid] = $child->name;
                }
            } else {
                $children = query_tab($crit);
                foreach ($children as $child) {
                    $options[$child->tid] = $child->name;
                }
            }
            $variables[$crit] = $options;
        }
    }
    // if is a taxonomy term
    if (isset($variables['page']['content']['system_main']['term_heading'])) {
        global $language;
        $langcode = $language->language;
        $tid = arg(2);
        $items = array();
        $children = taxonomy_get_children($tid);
        // if there is children change $cat_children
        if (!empty($children)) {
            $cat_children = $children;
            $variables['children'] = $children;
        } else {
            $parent_src = taxonomy_get_parents($tid);
            $parent = reset($parent_src)->tid;
            $cat_children = taxonomy_get_children($parent);
        }
        foreach ($cat_children as $cat_child) {
            $micros = query_micro_all($cat_child->tid);
            $cont = 0;
            foreach ($micros as $micro) {
                $cont++;
            }
            $micros_num = count($micros);
            $items[] = array('tid' => $cat_child->tid, 'name' => $cat_child->name, 'number_items' => $cont);
        }
        // load term
        $term = taxonomy_term_load($tid);
        // Text
        $description = field_get_items('taxonomy_term', $term, 'field_taxonomy_description');
        $description = field_view_value('taxonomy_term', $term, 'field_taxonomy_description', $description[0]);
        $term_img_src = file_load($term->field_taxonomy_image['und'][0]['fid']);
        $term_img = file_create_url($term_img_src->uri);
        $variables['term_img_header'] = $term_img;
        $variables['term_title'] = $term->name;
        $variables['term_description'] = $description;
        $variables['items_menu'] = $items;
        $variables['micros'] = fieldQueryMicro($tid);
        $variables['langcode'] = $langcode;
    }
}
function gd_sync_admin_entity_export_select_form ( $form, &$form_state ) {

    $handlers = module_invoke_all('gd_sync_entities');
    $exportHandlers = array();
    foreach ( $handlers as $h ) {
        $exportHandlers[] = $h['export'];
    }

    // sort by operation weight
    usort($exportHandlers,function($a,$b){
        if ($a['weight'] == $b['weight']) {
            return 0;
        }
        return ($a['weight'] < $b['weight']) ? -1 : 1;
    });

    $nodes = array();
    foreach ( $exportHandlers as $handler ) {
        $result = $handler['class']::getExportables($form_state['build_info']['args'][0]->nid);
        $nodes = array_merge($nodes,$result);
    }

    // Enable language column if translation module is enabled or if we have any
    // node with language.
    $multilanguage = (module_exists('translation') || db_query_range("SELECT 1 FROM {node} WHERE language <> :language", 0, 1, array(':language' => LANGUAGE_NONE))->fetchField());

    // Build the sortable table header.
    $header = array(
        'title' => array('data' => t('Title'), 'field' => 'n.title'),
        'type' => array('data' => t('Type'), 'field' => 'n.type'),
        'author' => t('Author'),
        'status' => array('data' => t('Status'), 'field' => 'n.status'),
        'changed' => array('data' => t('Updated'), 'field' => 'n.changed', 'sort' => 'desc')
    );
    if ($multilanguage) {
        $header['language'] = array('data' => t('Language'), 'field' => 'n.language');
    }
    $header['operations'] = array('data' => t('Operations'));

    // Prepare the list of nodes.
    $languages = language_list();
    $destination = drupal_get_destination();
    $options = array();
    foreach ($nodes as $node) {
        $langcode = entity_language('node', $node);
        $l_options = $langcode != LANGUAGE_NONE && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array();
        $options[$node->nid] = array(
            'title' => array(
                'data' => array(
                    '#type' => 'link',
                    '#title' => $node->title,
                    '#href' => 'node/' . $node->nid,
                    '#options' => $l_options,
                    '#suffix' => ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed))),
                ),
            ),
            'type' => $node->type,
            'author' => theme('username', array('account' => $node)),
            'status' => $node->status ? t('published') : t('not published'),
            'changed' => format_date($node->changed, 'short'),
        );
        if ($multilanguage) {
            if ($langcode == LANGUAGE_NONE || isset($languages[$langcode])) {
                $options[$node->nid]['language'] = $langcode == LANGUAGE_NONE ? t('Language neutral') : t($languages[$langcode]->name);
            }
            else {
                $options[$node->nid]['language'] = t('Undefined language (@langcode)', array('@langcode' => $langcode));
            }
        }
        // Build a list of all the accessible operations for the current node.
        $operations = array();
        if (node_access('update', $node)) {
            $operations['edit'] = array(
                'title' => t('edit'),
                'href' => 'node/' . $node->nid . '/edit',
                'query' => $destination,
            );
        }
        if (node_access('delete', $node)) {
            $operations['delete'] = array(
                'title' => t('delete'),
                'href' => 'node/' . $node->nid . '/delete',
                'query' => $destination,
            );
        }
        $options[$node->nid]['operations'] = array();
        if (count($operations) > 1) {
            // Render an unordered list of operations links.
            $options[$node->nid]['operations'] = array(
                'data' => array(
                    '#theme' => 'links__node_operations',
                    '#links' => $operations,
                    '#attributes' => array('class' => array('links', 'inline')),
                ),
            );
        }
        elseif (!empty($operations)) {
            // Render the first and only operation as a link.
            $link = reset($operations);
            $options[$node->nid]['operations'] = array(
                'data' => array(
                    '#type' => 'link',
                    '#title' => $link['title'],
                    '#href' => $link['href'],
                    '#options' => array('query' => $link['query']),
                ),
            );
        }
    }

    $form['nodes'] = array(
        '#type' => 'tableselect',
        '#header' => $header,
        '#options' => $options,
        '#empty' => t('No content available.'),
    );

    return $form;
}
 public function post($route, $form)
 {
     global $user;
     if ($route == 'comments.json') {
         $options = $this->getOptions();
         $node = node_load($options['nid']);
         if ($options['uid'] != $user->uid || !is_object($node)) {
             return false;
         }
         // Should we let the comment pass ?
         if ($node->comment != COMMENT_NODE_OPEN || !user_access('post comments')) {
             // Access denied.
             return false;
         }
         if (!empty($form->values['cid'])) {
             $comment = comment_load($form->values['cid']);
             if (!is_object($comment)) {
                 // Not existent CID.. Access denied
                 return false;
             }
             $nodeSubmittedComment = node_load($comment->nid);
             if (!is_object($nodeSubmittedComment) || $nodeSubmittedComment->nid != $node->nid) {
                 return FALSE;
                 // BAD nid.. Or node non existent
             }
             // Publish
             if ($form->values['toPublish']) {
                 if (user_access('administer comments') && user_access('post comments')) {
                     $comment->status = COMMENT_PUBLISHED;
                     comment_save($comment);
                 }
                 return;
             }
             // Deletion
             if ($form->values['toDelete']) {
                 if (user_access('administer comments') && user_access('post comments')) {
                     comment_delete($comment->cid);
                 }
                 return;
             }
             if (!comment_access('edit', $comment)) {
                 return FALSE;
                 // No access to edit the comment.
             }
         }
         if (empty($comment)) {
             $pid = NULL;
             if (!empty($form->values['pid'])) {
                 if ($form->values['pid'] == (int) $form->values['pid']) {
                     if ($comment_parent = comment_load((int) $form->values['pid'])) {
                         $pid = $form->values['pid'];
                     }
                 }
             }
             $comment = new stdClass();
             $comment->nid = $node->nid;
             $comment->pid = $pid;
             $comment->uid = $user->uid;
             $comment->name = check_plain($form->values['author']);
         }
         $comment->subject = check_plain($form->values['subject']);
         $field = field_info_field('comment_body');
         $langcode = field_is_translatable('comment', $field) ? entity_language('comment', $comment) : LANGUAGE_NONE;
         $field_infos = field_info_instance('comment', 'comment_body', 'comment_node_' . $node->type);
         $format = $options['comment-body-format'];
         $text_processing = $field_infos['settings']['text_processing'];
         $body = $form->values['body'];
         $body = $format != 'plain_text' && $text_processing ? check_markup($body, $format) : check_plain($body);
         if ($text_processing) {
             $comment->comment_body[$langcode][0]['format'] = $format;
         }
         $comment->comment_body = array($langcode => array());
         $comment->comment_body[$langcode][0]['value'] = $body;
         comment_submit($comment);
         comment_save($comment);
         cache_clear_all();
     }
 }