/** * Implements EntityReferenceHandler::getReferencableEntities(). */ public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) { $settings = $this->field['settings']['handler_settings']; $include_space = $settings['include_space']; $all_groups = oa_core_get_all_groups($match, $match_operator, $limit); $groups = array_map(create_function('$group', 'return $group->title;'), $all_groups); $group_options = array(); foreach ($groups as $nid => $group_name) { $group_options[$nid] = $group_name; } if ($space_id = oa_core_get_space_context()) { // Bring current group to front. if (!empty($group_options[$space_id])) { $group_options = array($space_id => t('!name (current)', array('!name' => $group_options[$space_id]))) + $group_options; } elseif ($include_space) { // NOTE: This title text is ignored and overwritten by select2widget // in select2widget_render_modes(). All that matters is the $space_id. // Current space should be cached. $space = node_load($space_id); if (empty($match) || stripos($space->title, $match) !== FALSE) { $group_options = array($space_id => t('- All space members -')) + $group_options; } } } return array(OA_GROUP_TYPE => $group_options); }
/** * implements hook_preprocess_page() * **/ function odsherredweb_preprocess_page(&$variables) { $current_theme = variable_get('theme_default', 'none'); // Search form $variables['simple_navigation_search'] = module_invoke('search', 'block_view', 'search'); // Navigation $variables['sidebar_borger'] = _bellcom_generate_menu('menu-indhold', 'sidebar'); $variables['sidebar_erhverv'] = _bellcom_generate_menu('menu-erhverv', 'sidebar'); $variables['sidebar_politik'] = _bellcom_generate_menu('menu-politik', 'sidebar'); // Add the site structure term id to the page div $node = node_load(arg(1)); if (is_object($node) && isset($node->field_os2web_spotbox_sitestruct)) { $termParents = taxonomy_get_parents($node->field_os2web_spotbox_sitestruct[LANGUAGE_NONE][0]['tid']); $termId = 'tid-' . $node->field_os2web_spotbox_sitestruct[LANGUAGE_NONE][0]['tid']; $termIdParent = ""; if (!empty($termParents)) { $termIdParent = 'tid-' . key($termParents); } $variables['attributes_array']['class'] = $termIdParent . ' ' . $termId; } // Paths $variables['path_js'] = base_path() . drupal_get_path('theme', $current_theme) . '/js'; $variables['path_img'] = base_path() . drupal_get_path('theme', $current_theme) . '/images'; $variables['path_css'] = base_path() . drupal_get_path('theme', $current_theme) . '/css'; $variables['path_font'] = base_path() . drupal_get_path('theme', $current_theme) . '/font'; }
function libya_cron_subscription_mail($data) { // subscription node $mail = $data[0]; $nids = $data[1]; // watchdog('actions', 'Cron subscription vars', func_get_args()); global $siteName, $isMail, $base_url; $isMail = TRUE; $body = '<h1 style="font-size:1.25em;">Your alert subscription results from ' . $siteName . '</h1> <p class="no-margin">The following results match your subscription alert.</p>'; foreach ($nids as $nid) { $N = node_load($nid); $content = strip_tags($N->body['und'][0]['value']); if (strlen($content) > 200) { $content = substr($content, 0, 200); } $CL = strrpos($content, ' '); $content = substr($content, 0, $CL) . '...'; $body .= '<h2 style="font-size:1.25em;">' . l($N->title, 'node/' . $N->nid, array('attributes' => array('style' => array('text-decoration' => 'none')))) . '</h2><p>' . $content . '</p> <p>' . t('read more: ') . l($base_url . '/' . drupal_lookup_path('alias', 'node/' . $N->nid), 'node/' . $N->nid, array('absolute' => TRUE)) . '</p> <hr/>'; } $data['message'] = 'Mail sent'; $to = $mail['mail']; $from = variable_get('site_mail', '*****@*****.**'); $params = array('body' => $body, 'rand' => $mail['rand'], 'to' => $to); $sent = drupal_mail('libya', 'subscription_alert_mail', $to, language_default(), $params, $from, TRUE); }
/** * Tests RSS enclosure formatter display for RSS feeds. */ function testFileFieldRSSContent() { $field_name = strtolower($this->randomMachineName()); $type_name = 'article'; $field_settings = array('display_field' => '1', 'display_default' => '1'); $instance_settings = array('description_field' => '1'); $widget_settings = array(); $this->createFileField($field_name, 'node', $type_name, $field_settings, $instance_settings, $widget_settings); // RSS display must be added manually. $this->drupalGet("admin/structure/types/manage/{$type_name}/display"); $edit = array("display_modes_custom[rss]" => '1'); $this->drupalPostForm(NULL, $edit, t('Save')); // Change the format to 'RSS enclosure'. $this->drupalGet("admin/structure/types/manage/{$type_name}/display/rss"); $edit = array("fields[{$field_name}][type]" => 'file_rss_enclosure'); $this->drupalPostForm(NULL, $edit, t('Save')); // Create a new node with a file field set. Promote to frontpage // needs to be set so this node will appear in the RSS feed. $node = $this->drupalCreateNode(array('type' => $type_name, 'promote' => 1)); $test_file = $this->getTestFile('text'); // Create a new node with the uploaded file. $nid = $this->uploadNodeFile($test_file, $field_name, $node->id()); // Get the uploaded file from the node. $node = node_load($nid, TRUE); $node_file = file_load($node->{$field_name}->target_id); // Check that the RSS enclosure appears in the RSS feed. $this->drupalGet('rss.xml'); $uploaded_filename = str_replace('public://', '', $node_file->getFileUri()); $test_element = array('key' => 'enclosure', 'value' => "", 'attributes' => array('url' => url("{$this->public_files_directory}/{$uploaded_filename}", array('absolute' => TRUE)), 'length' => $node_file->getSize(), 'type' => $node_file->getMimeType())); $this->assertRaw(format_xml_elements(array($test_element)), 'File field RSS enclosure is displayed when viewing the RSS feed.'); }
/** * Perform a single batch operation. * * Callback for batch_set(). * * @param $MULTIPLE_PARAMS * Additional parameters specific to the batch. These are specified in the * array passed to batch_set(). * @param $context * The batch context array, passed by reference. This contains the following * properties: * - 'finished': A float number between 0 and 1 informing the processing * engine of the completion level for the operation. 1 (or no value * explicitly set) means the operation is finished: the operation will not * be called again, and execution passes to the next operation or the * callback_batch_finished() implementation. Any other value causes this * operation to be called again; however it should be noted that the value * set here does not persist between executions of this callback: each time * it is set to 1 by default by the batch system. * - 'sandbox': This may be used by operations to persist data between * successive calls to the current operation. Any values set in * $context['sandbox'] will be there the next time this function is called * for the current operation. For example, an operation may wish to store a * pointer in a file or an offset for a large query. The 'sandbox' array key * is not initially set when this callback is first called, which makes it * useful for determining whether it is the first call of the callback or * not: * @code * if (empty($context['sandbox'])) { * // Perform set-up steps here. * } * @endcode * The values in the sandbox are stored and updated in the database between * http requests until the batch finishes processing. This avoids problems * if the user navigates away from the page before the batch finishes. * - 'message': A text message displayed in the progress page. * - 'results': The array of results gathered so far by the batch processing. * This array is highly useful for passing data between operations. After * all operations have finished, this is passed to callback_batch_finished() * where results may be referenced to display information to the end-user, * such as how many total items were processed. */ function callback_batch_operation($MULTIPLE_PARAMS, &$context) { if (!isset($context['sandbox']['progress'])) { $context['sandbox']['progress'] = 0; $context['sandbox']['current_node'] = 0; $context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT nid) FROM {node}')->fetchField(); } // For this example, we decide that we can safely process // 5 nodes at a time without a timeout. $limit = 5; // With each pass through the callback, retrieve the next group of nids. $result = db_query_range("SELECT nid FROM {node} WHERE nid > %d ORDER BY nid ASC", $context['sandbox']['current_node'], 0, $limit); while ($row = db_fetch_array($result)) { // Here we actually perform our processing on the current node. $node = node_load($row['nid'], NULL, TRUE); $node->value1 = $options1; $node->value2 = $options2; node_save($node); // Store some result for post-processing in the finished callback. $context['results'][] = check_plain($node->title); // Update our progress information. $context['sandbox']['progress']++; $context['sandbox']['current_node'] = $node->nid; $context['message'] = t('Now processing %node', array('%node' => $node->title)); } // Inform the batch engine that we are not finished, // and provide an estimation of the completion level we reached. if ($context['sandbox']['progress'] != $context['sandbox']['max']) { $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; } }
/** * {@inheritdoc} * * Pipe the 'meters' entry point to the relevant meter handler. */ public function viewEntities($ids_string) { $ids = array_unique(array_filter(explode(',', $ids_string))); $output = array(); $account = $this->getAccount(); foreach ($ids as $id) { $node = node_load($id); if ($node->type == 'iec_meter') { $resource = 'iec_meters'; } elseif ($node->type == 'modbus_meter') { $resource = 'modbus_meters'; } // The resource, by convention, is the plural form of the content-type // (for 'modbus_meter', it'll be 'modbus_meters'). $resource = $node->type . 's'; $handler = restful_get_restful_handler($resource); // Pipe the account. $handler->setAccount($account); // Get the meter. $output[] = $handler->viewEntity($id); } // Prepare summary data for the formatter. $this->prepareSummary($this); return $output; }
/** * Determine if a user has access to a certain operation within a group context. * * For content access @see hook_og_node_access(). * * @param $op * The operation name. * @param $node * The group or group content node object. * @param $acting_user * The user object of the acting user. * @param $account * Optional; The account related to the operation. * @return * OG_ACCESS_ALLOW - if operation is allowed; * OG_ACCESS_DENY - if it should be denied; * OG_ACCESS_IGNORE - if you don't care about this operation. */ function hook_og_access($op, $node, $acting_user, $account = NULL) { if ($op == 'view') { // Show group content only if they are in a certain day, defined in the // group's data. This data is fictional, and it's up to an implementing // module to implement it. if (og_is_group_content_type($node->type)) { // Get the first node group this group content belongs to. $gids = og_get_object_groups('node', $node); $group = node_load($gids[0]); if (!empty($group->data['show day'])) { $today = date('N'); if ($group->data['show day'] == $today) { return OG_ACCESS_ALLOW; } else { return OG_ACCESS_DENY; } } else { // The group doesn't have a day definition, so we don't care about this // operation. return OG_ACCESS_IGNORE; } } } }
function guifi_funders_validate($node) { /* * Validate funder(s) */ foreach ($node->funders as $k => $f) { guifi_log(GUIFILOG_TRACE, 'function guifi_funders_validate(m)', $f); if (!empty($f['supplier'])) { $mtemp = explode('-', $f['supplier']); if (is_numeric($mtemp[0])) { $supplier = node_load($mtemp[0]); } else { form_set_error('funders][' . $k . '][supplier', t('%supplier has to be registered as supplier/provider', array('%supplier' => $f['supplier']))); } } if (!empty($f['user'])) { $mtemp = explode('-', $f['user']); if (is_numeric($mtemp[0])) { $user = user_load($mtemp[0]); } else { form_set_error('funders][' . $k . '][user', t('%user has to be a valid user', array('%user' => $f['user']))); } } } guifi_log(GUIFILOG_TRACE, 'function guifi_funders_validate(funder)', $funder); }
/** * Returns field instances attached to the comment. * * @return array * An array of field instances. */ public function getFieldInstances() { $nid = $this->getNidValues(); $node = node_load($nid); $bundle = 'comment_node_' . $node->type; return field_info_instances('comment', $bundle); }
/** * {@inheritdoc} */ public function content() { // Get the list of the reservation node ids. $storage = \Drupal::entityManager()->getStorage('node'); $reserved_list = \Drupal::entityQuery('node')->condition('status', 1)->condition('type', 'balagan_reservation')->condition('field_balagan_reserv_accom', 'NULL', '<>')->condition('field_balagan_reserv_customer', 'NULL', '<>')->execute(); $reserved_accom = array(); $build = array(); foreach ($reserved_list as $nid) { $reserved_accom[] = $storage->load($nid)->field_balagan_reserv_accom->getValue()[0]['target_id']; } if (!empty($reserved_accom)) { $accommodations = \Drupal::entityQuery('node')->condition('status', 1)->condition('type', 'balagan_accommodation')->condition('nid', $reserved_accom, 'NOT IN')->execute(); foreach ($accommodations as $item) { $node = node_load($item); $locality = $node->field_balagan_accom_address->getValue()[0]['locality']; $start = $node->field_balagan_accom_date->getValue()[0]['value']; $end = $node->field_balagan_accom_date->getValue()[1]['value']; $people = $node->field_balagan_accom_people->getValue()[0]['value']; $link = $node->toLink()->toRenderable(); $build[] = $link; $build[] = array('markup' => array('#type' => 'markup', '#markup' => ' ' . $locality . ' ' . $start . ' - ' . $end . ' ' . 'Room for: ' . $people . '<BR>')); } } return $build; }
/** * Helper function to get the Box id number from the node. Includes * a check to see if the node is an organic group or not. */ public static function getBoxFolderID($gid) { // Is session active self::isSessionActive(); $node = node_load($gid); // ->soc_boxgroup_folder // if not group if (!og_is_group('node', $node)) { $msg = t('@node_title is not an Group', ['@node_title' => $node->title]); watchdog(self::BOX_OPERATIONS_NAME, $msg); drupal_set_message($msg, 'error'); return FALSE; } // return URL if we can $ent = entity_metadata_wrapper('node', $node); $box_id = $ent->soc_boxgroup_folder->value(); // if field is blank if (is_null($box_id)) { $msg = t('@node_title does not have a box folder url assigned to it', ['@node_title' => $node->title]); watchdog(SOC_BOXGROUP_MODULE_NAME, $msg); drupal_set_message($msg, 'error'); return FALSE; } // is it not numeric if (!is_numeric($box_id)) { watchdog(SOC_BOXGROUP_MODULE_NAME, t('@node_title (@nid) does not have a numeric folder id assigned to it', ['@node_title' => $node->title, '@nid' => $node->nid])); return FALSE; } // Lastly, if we get this far, just return the value; return $ent->soc_boxgroup_folder->value(); }
public function apply ( $patients ) { if ( !is_array($patients) ) { $patients = array($patients); } foreach ( $patients as $patient ) { \LogHelper::log_info('Applying ReportConfigRemoveColumnConfig treatment to: ' . $patient->reportNodeId); $node = node_load($patient->reportNodeId); $reportConfigText = get_node_field_value($node, 'field_report_conf', 0, 'value', FALSE); $reportConfig = isset($reportConfigText) ? json_decode($reportConfigText) : NULL; if (!isset($reportConfig)) { \LogHelper::log_info('Report configuration is EMPTY'); return; } // check column configs if (!empty($reportConfig->columnConfigs)) { foreach ($reportConfig->columnConfigs as $key => $value) { if (empty($value->columnId)) { unset($reportConfig->columnConfigs[$key]); } } $node->field_report_conf[$node->language][0]['value'] = json_encode($reportConfig); node_save($node); } } }
public function truncateColumnStorage(DataControllerCallContext $callcontext, DataSourceStructureHandler $datasourceStructureHandler, DatasetMetaData $dataset, $columnName) { $datasetNode = node_load($this->logicalDataset->nid); $datasetNode->field_dataset_records[$datasetNode->language][0]['value'] = 0; node_save($datasetNode); parent::truncateColumnStorage($callcontext, $datasourceStructureHandler, $dataset, $columnName); }
/** * Changes the permission a user has on the meta tags being edited. * * @param &$permission * TRUE, if the user can edit the current meta tag. * @param $object * An array describing the object to which the meta tag are associated. * @param $tag_name * The name of the meta tag. * @param $tag_info * An array describing the meta tag. */ function hook_nodewords_tags_permission_alter(&$permission, $object, $tag_name, $tag_info) { global $user; if (user_access('administer meta tags')) { $permission = TRUE; return; } if ($object['type'] == 'node' && ($node = node_load($options['id']))) { if ($user->uid == $node->uid && user_access("edit one's own node meta tags")) { $permission = TRUE; return; } if (user_access('edit any node meta tags')) { $permission = TRUE; } else { $permission = FALSE; } } elseif ($object['type'] == 'user' && ($account = user_load($object['id']))) { if ($user->uid == $account->uid && user_access("edit one's own user profile meta tags")) { $permission = TRUE; return; } if (user_access('edit any user profile meta tags')) { $permission = TRUE; } else { $permission = FALSE; } } }
/** * Implements hook_preprocess_node(). */ function dguk_preprocess_node(&$variables) { $variables['classes_array'][] = 'boxed'; $full_node = node_load($variables['node']->nid); $variables['title'] = $full_node->title; $variables['theme_hook_suggestions'][] = 'node__' . $variables['view_mode']; $variables['theme_hook_suggestions'][] = 'node__' . $variables['node']->type . '__' . $variables['view_mode']; if ($variables['node']->type == 'resource' || $variables['node']->type == 'book') { $variables['submitted'] = 'Submitted on ' . format_date($variables['created']); } $variables['updated'] = $variables['created'] != $variables['changed'] ? '| Updated on ' . format_date($variables['changed']) : FALSE; // We render user picture only on forum and blog nodes. if ($variables['node']->type == 'forum' || $variables['node']->type == 'blog') { $fields = field_info_instances('user', 'user'); $field_id = $fields['field_avatar']['field_id']; $user = new stdClass(); $user->uid = $variables['node']->uid; field_attach_load('user', array($user->uid => $user), FIELD_LOAD_CURRENT, array('field_id' => $field_id)); if (!empty($user->field_avatar)) { $field = field_get_items('user', $user, 'field_avatar'); $image = field_view_value('user', $user, 'field_avatar', $field[0], array('settings' => array('image_style' => 'avatar'))); } else { $image_info = dguk_default_field_image('field_avatar'); $image = field_view_value('user', $user, 'field_avatar', (array) $image_info, array('settings' => array('image_style' => 'avatar'))); } $colour = $variables['node']->uid % 10; if ($variables['node']->uid) { $variables['avatar'] = l(render($image), 'user/' . $variables['node']->uid, array('html' => true, 'attributes' => array('class' => array('field-avatar', 'bg-colour-' . $colour)))); } else { $variables['avatar'] = '<div class="field-avatar bg-colour-0">' . render($image) . '</div>'; } } }
/** * Tests that the autocomplete input element appears and the creation of a new * entity. */ public function testAutoCreate() { $user1 = $this->drupalCreateUser(array('access content', "create {$this->referencing_type} content")); $this->drupalLogin($user1); $this->drupalGet('node/add/' . $this->referencing_type); $this->assertFieldByXPath('//input[@id="edit-test-field-0-target-id" and contains(@class, "form-autocomplete")]', NULL, 'The autocomplete input element appears.'); $new_title = $this->randomMachineName(); // Assert referenced node does not exist. $base_query = \Drupal::entityQuery('node'); $base_query->condition('type', $this->referenced_type)->condition('title', $new_title); $query = clone $base_query; $result = $query->execute(); $this->assertFalse($result, 'Referenced node does not exist yet.'); $edit = array('title[0][value]' => $this->randomMachineName(), 'test_field[0][target_id]' => $new_title); $this->drupalPostForm("node/add/{$this->referencing_type}", $edit, 'Save'); // Assert referenced node was created. $query = clone $base_query; $result = $query->execute(); $this->assertTrue($result, 'Referenced node was created.'); $referenced_nid = key($result); $referenced_node = node_load($referenced_nid); // Assert the referenced node is associated with referencing node. $result = \Drupal::entityQuery('node')->condition('type', $this->referencing_type)->execute(); $referencing_nid = key($result); $referencing_node = node_load($referencing_nid); $this->assertEqual($referenced_nid, $referencing_node->test_field->target_id, 'Newly created node is referenced from the referencing node.'); // Now try to view the node and check that the referenced node is shown. $this->drupalGet('node/' . $referencing_node->id()); $this->assertText($referencing_node->label(), 'Referencing node label found.'); $this->assertText($referenced_node->label(), 'Referenced node label found.'); }
function gitp_page_alter(&$page) { if (arg(0) == 'node' && is_numeric(arg(1))) { $nid = arg(1); $node = node_load($nid); switch ($node->type) { case 'resources': $page['content_bottom'][] = field_view_field('node', $node, 'field_resources', 'full'); unset($page['content']['system_main']['nodes'][$nid]['field_resources']); break; case 'news': break; default: } } if (isset($page['content']['system_main']['term_heading'])) { // This is a taxonomy term page if ($page['content']['system_main']['term_heading']['term']['#entity_type'] == 'taxonomy_term') { $page['content_bottom']['system_main']['nodes'] = $page['content']['system_main']['nodes']; $page['content_bottom']['system_main']['pager'] = $page['content']['system_main']['pager']; unset($page['content']['system_main']['nodes']); unset($page['content']['system_main']['pager']); } } }
function addOg($selective = OG_OPEN) { $edit = array(); $edit['title'] = '!SimpleTest test group node! ' . $this->randomName(10); $edit['og_description'] = '!SimpleTest og description' . $this->randomName(10); $edit['body'] = '!SimpleTest test group welcome message! ' . $this->randomName(32) . ' ' . $this->randomName(32); $edit['og_selective'] = (string) $selective; $url = url('node/add/og', NULL, NULL, TRUE); $ret = $this->_browser->get($url); $this->assertTrue($ret, " [browser] GET {$url}"); foreach ($edit as $field_name => $field_value) { $ret = $this->_browser->setFieldByName("edit[{$field_name}]", $field_value); $this->assertTrue($ret, " [browser] Setting edit[{$field_name}]=\"{$field_value}\""); } $this->_browser->setFieldByName('edit[og_theme]', ''); // May not be present, so no error catching $ret = $this->_browser->clickSubmit(t('Submit')); // $ret = $this->_browser->clickSubmitByName('op'); $this->assertTrue($ret, ' [browser] POST by click on ' . t('Submit')); $this->_content = $this->_browser->getContent(); $this->assertWantedText(t('Your %post was created.', array('%post' => 'group')), 'Group created'); $node = node_load(array('title' => $edit['title'])); $this->assertNotNull($node, 'Group found in database. %s'); $this->_cleanupGroups[] = $node->nid; return $node->nid; }
public function apply ( $patients ) { if ( !is_array($patients) ) { $patients = array($patients); } foreach ( $patients as $patient ) { \LogHelper::log_info('Applying ReportConfigRemoveFilter treatment to: ' . $patient->reportNodeId); $node = node_load($patient->reportNodeId); $reportConfigText = get_node_field_value($node, 'field_report_conf', 0, 'value', FALSE); $reportConfig = isset($reportConfigText) ? json_decode($reportConfigText) : NULL; if (!isset($reportConfig)) { \LogHelper::log_info('Report configuration is EMPTY'); return; } // check column configs if (!empty($reportConfig->model->filters)) { $preservedFilters = array(); foreach ($reportConfig->model->filters as $key => $filter) { if ( $patient->filter != $filter ) { $preservedFilters[] = $filter; } } $reportConfig->model->filters = $preservedFilters; $node->field_report_conf[$node->language][0]['value'] = json_encode($reportConfig); node_save($node); } } }
/** * Test node creation by editor. * * 1. Editor creates Draft node * 2. Editor set status from Draft to Final Draft * 3. The node appears in the users's overview screen. */ public function testModerateToBeApproved() { $this->loginAs('editor1'); $node = $this->drupalCreateNode(array('language' => 'en', 'title' => $this->nodeTitle1, 'type' => 'news', 'workbench_access' => 1007)); workbench_moderation_moderate($node, 'final_draft'); $this->loginAs('review_manager1'); // Set node status To Be Reviewed. $options = array('title_field[en][0][value]' => $this->nodeTitle1, 'workbench_moderation_state_new' => 'needs_review'); $this->drupalPost("node/{$node->nid}/edit", $options, t('Save')); entity_get_controller('node')->resetCache(array($node->nid)); $node = node_load($node->nid); $this->assertEquals('needs_review', $node->workbench_moderation['current']->state); // Set the reviewer to project_manager1 $pm1 = user_load_by_name('project_manager1'); $options = array('project_manager' => $pm1->uid); $this->drupalPost("node/{$node->nid}/review", $options, t('Change')); $this->drupalGet("node/{$node->nid}/review"); $this->assertText('project_manager1'); // Define the list of approvers. // Cannot use drupalPost here. $ap1 = user_load_by_name('approver1'); $ap2 = user_load_by_name('approver2 '); $form_state = array('node' => $node, 'values' => array('rows' => array($ap1->uid => array('weight' => -10), $ap2->uid => array('weight' => -11)))); module_load_include('inc', 'osha_workflow', 'osha_workflow.admin'); drupal_form_submit('osha_workflow_node_approval_form', $form_state, $node); $this->drupalGet("node/{$node->nid}/approve"); $this->assertText($ap1->name); $this->assertText($ap2->name); $this->loginAs('project_manager1'); $options = array('workbench_moderation_state_new' => 'to_be_approved'); $this->drupalPost("node/{$node->nid}/edit", $options, t('Save')); entity_get_controller('node')->resetCache(array($node->nid)); $node = node_load($node->nid); $this->assertEquals('to_be_approved', $node->workbench_moderation['current']->state); }
function insert_door_to_drupal($door_id) { // set HTTP_HOST or drupal will refuse to bootstrap $_SERVER['HTTP_HOST'] = 'zl-apps'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; include_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $door = new Door(); $door_detail = $door->read(null, $door_id); $door_nid = null; $query = new EntityFieldQuery(); $entities = $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'doors')->propertyCondition('status', 1)->fieldCondition('field_door_id', 'value', $door_detail['Door']['id'], '=')->execute(); foreach ($entities['node'] as $nid => $value) { $door_nid = $nid; break; // no need to loop more even if there is multiple (it is supposed to be unique } $node = null; if (is_null($door_nid)) { $node = new stdClass(); $node->language = LANGUAGE_NONE; } else { $node = node_load($door_nid); } $node->type = 'doors'; node_object_prepare($node); $node->title = $door_detail['Door']['door_style']; $node->field_door_id[$node->language][0]['value'] = $door_detail['Door']['id']; $node->sell_price = 0; $node->model = $door_detail['Door']['door_style']; $node->shippable = 1; $path = 'door/' . $node->title; $node->path = array('alias' => $path); node_save($node); }
private function content_ajax_page_fc($fcid) { $fcitem = \Drupal\field_collection\Entity\FieldCollectionItem::load($fcid); $target = WG::entity_get_field_value($fcitem, 'field_target'); preg_match('%^([^:]+)://([0-9]+)$%', $target, $m); $itemtype = $m[1]; $id = $m[2]; switch ($itemtype) { case 'public318': $identifier = $id; $text = WG::entity_get_field_formatted_text($fcitem, 'field_annotation'); $stylename = 'large'; $icon_uri = _expo_public318_get_icon_uri($identifier); $icontag = WG::render_styled_image($icon_uri, $stylename); $output = '<div class="sticky-fc-public318">' . '<div class="collicon">' . _expo_coll_url($identifier, $icontag) . '</div>' . '<div class="colltext">' . $text . '</div>' . '</div>'; break; case 'storynode': $nid = $id; $story = node_load($nid); $v = entity_view($story, 'ajaxpage'); $output = render($v); break; default: $tag = "<div class=\"sticky\" id=\"sticky_{$pos}\">" . $itemtype . $pos . "</div>"; } $build = ['#markup' => $output]; return $build; }
/** * Overrides RestfulEntityBase::getFormSchemaAllowedValues(). * * For OG vocab fields we get only the ones of the group passed context. */ protected function getFormSchemaAllowedValues($field) { if ($field['field_name'] == 'c4m_related_document') { // We don't need allowed values for related documents, because we are // getting them from library. return array(); } if ($field['field_name'] != OG_VOCAB_FIELD) { return parent::getFormSchemaAllowedValues($field); } $request = $this->getRequest(); if (empty($request['group']) || !intval($request['group'])) { throw new \RestfulBadRequestException('The "group" parameter is missing for the request, thus the vocabulary cannot be set for the group.'); } $node = node_load($request['group']); if (!$node) { throw new \RestfulBadRequestException('The "group" parameter is not a node.'); } elseif ($node->type != 'group') { throw new \RestfulBadRequestException('The "group" parameter is not a of type "group".'); } $return = array(); foreach (array('tags', 'categories') as $vocab_name) { $allowed_values = array(); $og_vocab = c4m_restful_get_og_vocab_by_name('node', $node->nid, $vocab_name); $vocab = taxonomy_vocabulary_load($og_vocab[0]->vid); $allowed_values[] = array('vocabulary' => $vocab->machine_name, 'parent' => 0); $field['settings']['allowed_values'] = $allowed_values; $return[$vocab_name] = taxonomy_allowed_values($field); } return $return; }
/** * Checks that unchecking 'Create new revision' works when editing a node. */ function testNodeFormSaveWithoutRevision() { // Set page revision setting 'create new revision'. This will mean new // revisions are created by default when the node is edited. $type = entity_load('node_type', 'page'); $type->settings['node']['options']['revision'] = TRUE; $type->save(); // Create the node. $node = $this->drupalCreateNode(); // Verify the checkbox is checked on the node edit form. $this->drupalGet('node/' . $node->id() . '/edit'); $this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked"); // Uncheck the create new revision checkbox and save the node. $edit = array('revision' => FALSE); $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); // Load the node again and check the revision is the same as before. $node_revision = node_load($node->id(), TRUE); $this->assertEqual($node_revision->getRevisionId(), $node->getRevisionId(), "After an existing node is saved with 'Create new revision' unchecked, a new revision is not created."); // Verify the checkbox is checked on the node edit form. $this->drupalGet('node/' . $node->id() . '/edit'); $this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked"); // Submit the form without changing the checkbox. $edit = array(); $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); // Load the node again and check the revision is different from before. $node_revision = node_load($node->id(), TRUE); $this->assertNotEqual($node_revision->getRevisionId(), $node->getRevisionId(), "After an existing node is saved with 'Create new revision' checked, a new revision is created."); }
/** * Tests the normal formatter display on node display. */ function testUploadPath() { $field_name = strtolower($this->randomMachineName()); $type_name = 'article'; $this->createFileField($field_name, 'node', $type_name); $test_file = $this->getTestFile('text'); // Create a new node. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); // Check that the file was uploaded to the file root. $node = node_load($nid, TRUE); $node_file = file_load($node->{$field_name}->target_id); $this->assertPathMatch('public://' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri()))); // Change the path to contain multiple subdirectories. $this->updateFileField($field_name, $type_name, array('file_directory' => 'foo/bar/baz')); // Upload a new file into the subdirectories. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); // Check that the file was uploaded into the subdirectory. $node = node_load($nid, TRUE); $node_file = file_load($node->{$field_name}->target_id, TRUE); $this->assertPathMatch('public://foo/bar/baz/' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri()))); // Check the path when used with tokens. // Change the path to contain multiple token directories. $this->updateFileField($field_name, $type_name, array('file_directory' => '[current-user:uid]/[current-user:name]')); // Upload a new file into the token subdirectories. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); // Check that the file was uploaded into the subdirectory. $node = node_load($nid, TRUE); $node_file = file_load($node->{$field_name}->target_id); // Do token replacement using the same user which uploaded the file, not // the user running the test case. $data = array('user' => $this->admin_user); $subdirectory = \Drupal::token()->replace('[user:uid]/[user:name]', $data); $this->assertPathMatch('public://' . $subdirectory . '/' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path with token replacements.', array('%file' => $node_file->getFileUri()))); }
function suitcase_preprocess_region(&$vars) { if ($vars['region'] == 'content' && arg(0) == 'node' && is_numeric(arg(1)) && arg(2) !== 'edit') { $node = node_load(arg(1)); if ($node->type == 'people' && !empty($node->field_people_category)) { $vars['categories'] = array(); foreach ($node->field_people_category[LANGUAGE_NONE] as $category) { $tax = taxonomy_term_load($category['tid']); array_push($vars['categories'], $tax->name); } } } else { if ($vars['region'] == 'branding') { // Prepare Logo $vars['suitcase_config_logo'] = FALSE; $logo = variable_get('suitcase_config_logo'); $vars['site_name'] = variable_get('site_name'); if ($logo) { $logo_url = file_create_url($logo['uri']); $vars['suitcase_config_logo'] = '<div class="logo-img"><a href="' . $GLOBALS['base_url'] . '" rel="home" title="' . $vars['site_name'] . '" class="active"><img src="' . $logo_url . '" alt="Go to ' . $vars['site_name'] . ' home" id="logo" /></a></div>'; } $vars['dept_url'] = variable_get('dept_url', $default = NULL); $vars['show_isu_nameplate'] = variable_get('suitcase_config_isu_nameplate_display', 1); } } }
/** * Add link to view full-sized image in colorbox and add caption */ function gettysw_preprocess_field(&$vars, $hook) { foreach ($vars['element']['#items'] as $delta => $item) { if (!empty($vars['element'][$delta])) { if (module_exists('image_field_caption') && isset($item['image_field_caption'])) { $vars['items'][$delta]['caption'] = check_markup($item['image_field_caption']['value'], $item['image_field_caption']['format']); } if ($vars['element']['#field_name'] == 'field_image' && isset($item['uri']) && module_exists('colorbox') && empty($vars['element']['#object']->is_export)) { $vars['items'][$delta]['colorbox_link'] = '<a class="colorbox" href="' . file_create_url($item['uri']) . '">Expand Image</a>'; } if ($vars['element']['#field_name'] == 'field_image_reference_info' && $vars['element']['#view_mode'] == 'full') { drupal_add_css(drupal_get_path('module', 'lighttable') . '/lighttable.css'); $vars['content_attributes_array'] = array('id' => 'lighttable'); foreach ($vars['items'] as $delta => $item) { $fc_item = reset($vars['items'][$delta]['entity']['field_collection_item']); $image_entity = $fc_item['#entity']->field_image_reference[LANGUAGE_NONE][0]['entity']; $file_nodes = file_usage_list($image_entity); $image_node = node_load(key($file_nodes['file']['node'])); $vars['items'][$delta]['entity']['field_collection_item']['title'] = array('#markup' => '<span class="field-title">' . $image_node->title . '</span>', '#weight' => -1); $left = $fc_item['#entity']->field_x_pos[LANGUAGE_NONE][0]['value']; $top = $fc_item['#entity']->field_y_pos[LANGUAGE_NONE][0]['value']; $width = $fc_item['#entity']->field_width[LANGUAGE_NONE][0]['value']; $height = $fc_item['#entity']->field_height[LANGUAGE_NONE][0]['value']; $vars['items'][$delta]['#attributes']['style'] = "position: absolute; top: {$top}px; left: {$left}px; width: {$width}px; height: {$height}px;"; $vars['items'][$delta]['#attributes']['class'][] = 'lighttable-image-container'; } } } } }
/** * Tests file access for file uploaded to a private node. */ function testPrivateFile() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $this->createFileField($field_name, 'node', $type_name, array('uri_scheme' => 'private')); // Create a field with no view access. See // field_test_entity_field_access(). $no_access_field_name = 'field_no_view_access'; $this->createFileField($no_access_field_name, 'node', $type_name, array('uri_scheme' => 'private')); $test_file = $this->getTestFile('text'); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name, TRUE, array('private' => TRUE)); $node = node_load($nid, TRUE); $node_file = file_load($node->{$field_name}->target_id); // Ensure the file can be downloaded. $this->drupalGet(file_create_url($node_file->getFileUri())); $this->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the shipped file.'); $this->drupalLogOut(); $this->drupalGet(file_create_url($node_file->getFileUri())); $this->assertResponse(403, 'Confirmed that access is denied for the file without the needed permission.'); // Test with the field that should deny access through field access. $this->drupalLogin($this->admin_user); $nid = $this->uploadNodeFile($test_file, $no_access_field_name, $type_name, TRUE, array('private' => TRUE)); $node = node_load($nid, TRUE); $node_file = file_load($node->{$no_access_field_name}->target_id); // Ensure the file cannot be downloaded. $this->drupalGet(file_create_url($node_file->getFileUri())); $this->assertResponse(403, 'Confirmed that access is denied for the file without view field access permission.'); }
/** * Implemensts hook_breadcrumb(). * * tth@bellcom.dk check if there is a better way to do this... */ function cmstheme_breadcrumb($variables) { $breadcrumb = $variables['breadcrumb']; $nid = arg(1); if (is_numeric($nid)) { $node = node_load($nid); } if (!empty($breadcrumb)) { $output = '<div class="breadcrumb you-are-here">' . t('Du er her: ') . '</div>'; $title = drupal_get_title(); $breadcrumb[0] = l(t('Forside'), '<front>', array('attributes' => array('title' => 'Forside'))); $breadcrumb[] = '<a href="#" title="' . $title . '">' . $title . '</a>'; if ($title == 'Søg') { unset($breadcrumb); $breadcrumb[0] = l(t('Forside'), '<front>', array('attributes' => array('title' => 'Forside'))); $breadcrumb[] = '<a href="#" title="Søgning">Søgning</a>'; } if (isset($node) && is_object($node) && $node->type == 'meeting') { unset($breadcrumb); $breadcrumb[0] = l(t('Forside'), '<front>', array('attributes' => array('title' => 'Forside'))); $breadcrumb[] = l(t('Politik & planer'), 'politik-og-planer', array('attributes' => array('title' => 'Politik og planer'))); $breadcrumb[] = l(t('Søg i dagsordener og referater'), 'dagsorden-og-referat', array('attributes' => array('title' => 'Søg i dagsordner og referater'))); $breadcrumb[] = l(t($title), '#'); } $output .= '<div class="breadcrumb">' . implode('<div class="bread-crumb"> > </div> ', $breadcrumb) . '</div>'; return $output; } }
/** * HOOK_builder_content_view() */ function HOOK_builder_content_view($delta = '', $content = array()) { $content = ''; switch ($delta) { case 'node': $node_content = ''; if (!empty($content['settings']['nid'])) { $nid = $content['settings']['nid']; if ($node = node_load($nid)) { if (isset($content['settings']['hide_node_title']) && $content['settings']['hide_node_title']) { // hide node title. $node->title = FALSE; } $node_view = node_view($node, $content['settings']['view_mode']); $node_content = render($node_view); } } $content['content'] = $node_content; break; case 'custom_text': $custom_text_value = isset($content['settings']['custom_text']['value']) ? $content['settings']['custom_text']['value'] : ''; if (isset($content['settings']['custom_text']['format'])) { $custom_text_value = check_markup($custom_text_value, $content['settings']['custom_text']['format']); } $content['content'] = $custom_text_value; break; return $content; } }