/** * {@inheritdoc} */ public function buildForm(array $form, array &$form_state, $key = '') { // Get the old value $old_value = \Drupal::state()->get($key); // First we will show the user the content of the variable about to be edited $form['old_value'] = array('#type' => 'item', '#title' => t('Old value for %name', array('%name' => $key)), '#markup' => kprint_r($old_value, TRUE)); // Store in the form the name of the state variable $form['state_name'] = array('#type' => 'hidden', '#value' => $key); // Only simple structures are allowed to be edited. $disabled = !$this->checkObject($old_value); // Set the transport format for the new value. Values: // - plain // - yaml $form['transport'] = array('#type' => 'hidden', '#value' => 'plain'); if (is_array($old_value)) { $dumper = new Dumper(); // Set Yaml\Dumper's default indentation for nested nodes/collections to // 2 spaces for consistency with Drupal coding standards. $dumper->setIndentation(2); // The level where you switch to inline YAML is set to PHP_INT_MAX to // ensure this does not occur. $old_value = $dumper->dump($old_value, PHP_INT_MAX); $form['transport']['#value'] = 'yaml'; } $form['new_value'] = array('#type' => 'textarea', '#title' => t('New value'), '#default_value' => $disabled ? '' : $old_value, '#disabled' => $disabled); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save')); $form['actions']['cancel'] = array('#type' => 'link', '#title' => t('Cancel'), '#href' => 'devel/state'); return $form; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $state_name = '') { // Get the old value $old_value = $this->state->get($state_name); if (!isset($old_value)) { drupal_set_message(t('State @name does not exist in the system.', array('@name' => $state_name)), 'warning'); return; } // Only simple structures are allowed to be edited. $disabled = !$this->checkObject($old_value); if ($disabled) { drupal_set_message(t('Only simple structures are allowed to be edited. State @name contains objects.', array('@name' => $state_name)), 'warning'); } // First we will show the user the content of the variable about to be edited. $form['value'] = array('#type' => 'item', '#title' => $this->t('Current value for %name', array('%name' => $state_name)), '#markup' => kprint_r($old_value, TRUE)); $transport = 'plain'; if (!$disabled && is_array($old_value)) { try { $old_value = Yaml::encode($old_value); $transport = 'yaml'; } catch (InvalidDataTypeException $e) { drupal_set_message(t('Invalid data detected for @name : %error', array('@name' => $state_name, '%error' => $e->getMessage())), 'error'); return; } } // Store in the form the name of the state variable $form['state_name'] = array('#type' => 'value', '#value' => $state_name); // Set the transport format for the new value. Values: // - plain // - yaml $form['transport'] = array('#type' => 'value', '#value' => $transport); $form['new_value'] = array('#type' => 'textarea', '#title' => $this->t('New value'), '#default_value' => $disabled ? '' : $old_value, '#disabled' => $disabled, '#rows' => 15); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save'), '#disabled' => $disabled); $form['actions']['cancel'] = array('#type' => 'link', '#title' => $this->t('Cancel'), '#url' => Url::fromRoute('devel.state_system_page')); return $form; }
/** * Writes a krumo entry into the watchdog log, if Devel is installed. */ function wpm($input, $name = NULL) { if (module_exists('devel') && user_access('access devel information')) { $export = kprint_r($input, TRUE, $name); watchdog('debug', $export); } }
/** * Builds the session overview page. * * @return array * Array of page elements to render. */ public function session() { $output['description'] = array('#markup' => '<p>' . $this->t('Here are the contents of your $_SESSION variable.') . '</p>'); $output['session'] = array('#type' => 'table', '#header' => array($this->t('Session name'), $this->t('Session ID')), '#rows' => array(array(session_name(), session_id())), '#empty' => $this->t('No session available.')); $output['data'] = array('#markup' => kprint_r($_SESSION, TRUE)); return $output; }
/** * Menu callback: display the session. */ public function session() { $output = kprint_r($_SESSION, TRUE); $headers = array(t('Session name'), t('Session ID')); // @todo don't call theme() directly. $output .= theme('table', array('headers' => $headers, 'rows' => array(array(session_name(), session_id())))); return $output; }
// Start an infinite loop, we will break out of this loop programmatically // Ensure the PHP thread does not time-out set_time_limit(900); // Try to grab 100 articles from api.trade.gov/$tradeContentToConsume/search starting at $offset $jsonString = file_get_contents("http://api.trade.gov/{$tradeContentToConsume}/search?offset={$offset}&size=100"); $jsonData = json_decode($jsonString, true); // Check if we got (any) results/articles from $offset if (empty($jsonData['results']) || count($jsonData['results']) === 0) { // If we got no results/articles, then that means there are no more articles to pull from api.trade.gov/$tradeContentToConsume/search break; } else { // 100 (or less) articles were returned from this API call, we shall merge this result-array into $tradeDotGovArticles $tradeDotGovArticles = array_merge($tradeDotGovArticles, $jsonData['results']); $offset += 100; // Increment $offset by 100 so that we can grab the NEXT 100 articles offered by api.trade.gov/$tradeContentToConsume/search } } // Return array('results', 'total'), the same structure as returned from the API as seen here: http://api.trade.gov/$tradeContentToConsume/search?offset=0&size=100 return array('results' => $tradeDotGovArticles, 'total' => count($tradeDotGovArticles)); } } $results = _getAllContentFromApiDotTradeDotGov('trade_events'); if (empty($_GET['debug']) || intval($_GET['debug']) !== 1) { @ob_end_clean(); while (@ob_end_clean()) { } print json_encode($results); exit; } else { kprint_r($results); }
<div id="node-<?php print $node->nid; ?> " class="<?php print $classes; ?> " xmlns="http://www.w3.org/1999/html"> </div> <?php /** * Created by PhpStorm. * User: naga.tejaswini * Date: 9/18/14 * Time: 1:33 PM */ kprint_r($node); ?> <div class="country-com-guide-maincontent"> <label class="lblclass">Description :</label> <?php print $node->field_ccguide_description['und'][0]['value']; ?> <br/> <!-- Expiration Date --> <?php if (!empty($node->field_ccguide_expiration_date['und'][0]['value'])) { ?> <div class="expiration-date-field"> <b><label class="lblclass">Expiration Date : </label></b>
<?php kprint_r($_REQUEST); // Create an renderable array for wizard results, to send into: theme('yawizard_sections' <RenderableArray>) $wizardResultsRenderableArray = array('sections' => array(), 'titles' => array(), 'legend' => array()); // Define two sections to show, we will reference them as "pets" and "techies" - these are only machine name, not human readable labels // They will be used as CSS classes in the rendered output, but not visible to humans. $wizardResultsRenderableArray['sections'] = array('pets' => array(), 'techies' => array()); // Here we will give the 2 sections human-readable titles/labels $wizardResultsRenderableArray['titles'] = array('pets' => 'As a pet owner, you may be interested in', 'techies' => 'Tech information you may be interested in'); // We will have the yawizard_sections.tpl.php template render a legend (this is optional). This will show at the top of the results slide. $wizardResultsRenderableArray['legend'] = array('pets' => array('title' => 'Pet Info', 'img' => 'sites/all/themes/bizusa/images/content-type-icons-small/program.png'), 'techies' => array('title' => 'Tech Info', 'img' => 'sites/all/themes/bizusa/images/content-type-icons-small/tools.png')); // Now we will populate results into the "pets" section of thw wizard results if (intval($_REQUEST['inputs']['has_pets']) === 1) { if (intval($_REQUEST['inputs']['pet_dog']) === 1) { for ($x = 0; $x < 3; $x++) { $wizardResultsRenderableArray['sections']['pets'][] = array('title' => 'Something a dog owner may be interested in ' . ($x + 1), 'link' => 'http://google.com/', 'snippet' => 'This is a snippet implemented in line ' . __LINE__, 'tags' => 'dog tag1 tag2', 'tag_count' => 3, 'all_tags' => array(), 'type' => 'pets', 'promoted' => 0); } } if (intval($_REQUEST['inputs']['pet_cat']) === 1) { for ($x = 0; $x < 4; $x++) { $wizardResultsRenderableArray['sections']['pets'][] = array('title' => 'Something a cat owner may be interested in ' . ($x + 1), 'link' => 'http://google.com/', 'snippet' => 'This is a snippet implemented in line ' . __LINE__, 'tags' => 'cat tag1 tag2', 'tag_count' => 3, 'all_tags' => array(), 'type' => 'pets', 'promoted' => 0); } } } // Now we will populate results into the "techies" section of thw wizard results if (intval($_REQUEST['inputs']['tech_guru']) === 1) { if (intval($_REQUEST['inputs']['tech_security']) === 1) { for ($x = 0; $x < 3; $x++) { $wizardResultsRenderableArray['sections']['techies'][] = array('title' => 'Something a security-person may be interested in ' . ($x + 1), 'link' => 'http://google.com', 'snippet' => 'This is a snippet', 'tags' => 'tag1 tag2', 'tag_count' => 2, 'all_tags' => array(), 'type' => 'techies', 'promoted' => 0); }
// Enforce the MIME-Type HTTP-Responce-Header foreach ($pageData['special-headers'] as $specialHeader) { header($specialHeader); } // If the target export.gov content is an image/pdf/Excel/file-attachment, return it alone, and terminate this PHP thread if ($pageData['is-image'] === true || $pageData['is-file-attachment'] === true) { // Destroy every currently held in the output buffer, since we want ONLY data in $pageData['export-data-source'] to be sent to the client-browser @ob_end_clean(); while (@ob_end_clean()) { } // If no file-name for the attachment was given in the HTTP-response header, set one now if (stripos(implode('-', $pageData['special-headers']), 'filename=') === false) { $fileName = basename(parse_url($pageData['url'], PHP_URL_PATH)); header('Content-Disposition: attachment; filename="' . $fileName . '"'); } // Send the image/pdf/exel raw-data into the web-socket (to the client-browser) print $pageData['export-data-source']; exit; // Terminate this PHP thread } // Debug and verbosity print ' <!-- The following debug data is rendered from export-portal.tpl.php --> <div class="debug-info debuginfo-ripdata admin-only"> ' . kprint_r($pageData, true) . ' </div> '; $variables = array('exportTitle' => $pageData['title'], 'exportContentHTML' => $pageData['content-html'], 'exportSideBars' => $pageData['navigation-links'], 'exportCachePath' => $pageData['storage-filepath']); // With the $pageData obtained, render this information in the appropriate template //dsm($variables); print theme('export_portal_page', $variables);