/** * {@inheritdoc} */ protected function generateElements(array $values) { $num = $values['num']; $kill = $values['kill']; $pass = $values['pass']; $age = $values['time_range']; $roles = $values['roles']; $url = parse_url($GLOBALS['base_url']); if ($kill) { $uids = db_select('users', 'u')->fields('u', array('uid'))->condition('uid', 1, '>')->execute()->fetchAllAssoc('uid'); user_delete_multiple(array_keys($uids)); $this->setMessage(\Drupal::translation()->formatPlural(count($uids), '1 user deleted', '@count users deleted.')); } if ($num > 0) { $names = array(); while (count($names) < $num) { //@todo add suport for devel_generate_word(mt_rand(6, 12)) in a class method $name = $this->generateWord(mt_rand(6, 12)); $names[$name] = ''; } if (empty($roles)) { $roles = array(DRUPAL_AUTHENTICATED_RID); } foreach ($names as $name => $value) { $edit = array('uid' => NULL, 'name' => $name, 'pass' => $pass, 'mail' => $name . '@example.com', 'status' => 1, 'created' => REQUEST_TIME - mt_rand(0, $age), 'roles' => array_combine($roles, $roles), 'devel_generate' => TRUE); $account = entity_create('user', $edit); // Populate all fields with sample values. $this->populateFields($account); $account->save(); } } $this->setMessage(t('!num_users created.', array('!num_users' => format_plural($num, '1 user', '@count users')))); }
function update_script_selection_form($form, &$form_state) { $count = 0; $form['start'] = array('#tree' => TRUE, '#type' => 'fieldset', '#collapsed' => TRUE, '#collapsible' => TRUE); // Ensure system.module's updates appear first $form['start']['system'] = array(); $updates = update_get_update_list(); foreach ($updates as $module => $update) { if (!isset($update['start'])) { $form['start'][$module] = array('#title' => $module, '#item' => $update['warning'], '#prefix' => '<div class="warning">', '#suffix' => '</div>'); continue; } if (!empty($update['pending'])) { $form['start'][$module] = array('#type' => 'hidden', '#value' => $update['start']); $form['start'][$module . '_updates'] = array('#markup' => theme('item_list', array('items' => $update['pending'], 'title' => $module . ' module'))); } if (isset($update['pending'])) { $count = $count + count($update['pending']); } } if (empty($count)) { drupal_set_message(t('No pending updates.')); unset($form); $form['links'] = array('#markup' => theme('item_list', array('items' => update_helpful_links()))); } else { $form['help'] = array('#markup' => '<p>The version of Drupal you are updating from has been automatically detected.</p>', '#weight' => -5); $form['start']['#title'] = format_plural($count, '1 pending update', '@count pending updates'); $form['has_js'] = array('#type' => 'hidden', '#default_value' => FALSE); $form['submit'] = array('#type' => 'submit', '#value' => 'Apply pending updates'); } return $form; }
/** * Format a time interval with the requested granularity. * * @param $timestamp * The length of the interval in seconds. * @param $granularity * How many different units to display in the string. * @param $langcode * Optional language code to translate to a language other than * what is used to display the page. * @return * A translated string representation of the interval. */ function format_interval($timestamp, $granularity = 2, $langcode = NULL) { $units = array( '1 year|@count years' => 31536000, '1 month|@count months' => 2592000, '1 week|@count weeks' => 604800, '1 day|@count days' => 86400, '1 hour|@count hours' => 3600, '1 min|@count min' => 60, '1 sec|@count sec' => 1 ); $output = ''; foreach ($units as $key => $value) { $key = explode('|', $key); if ($timestamp >= $value) { $output .= ($output ? ' ' : '') . format_plural(floor($timestamp / $value), $key[0], $key[1], array(), array('langcode' => $langcode)); $timestamp %= $value; $granularity--; } if ($granularity == 0) { break; } } return $output ? $output : t('0 sec', array(), array('langcode' => $langcode)); }
/** * Overrides \Drupal\views\Plugin\views\pager\PagerPluginBase::summaryTitle(). */ public function summaryTitle() { if (!empty($this->options['offset'])) { return format_plural($this->options['items_per_page'], '@count item, skip @skip', 'Paged, @count items, skip @skip', array('@count' => $this->options['items_per_page'], '@skip' => $this->options['offset'])); } return format_plural($this->options['items_per_page'], '@count item', 'Paged, @count items', array('@count' => $this->options['items_per_page'])); }
function md_hosoren_facetapi_count($variables) { $count = (int) $variables['count']; $one_item = t('pc.'); $more_items = t('pcs.'); //pcs. $output = format_plural($count, '1 ' . $one_item, '@count ' . $more_items); return '<span class="facet-count">(' . $output . ')</span>'; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $filter_values = $this->translateFilterValues(); $langcode = $filter_values['langcode']; $this->languageManager->reset(); $languages = language_list(); $langname = isset($langcode) ? $languages[$langcode]->name : "- None -"; $form['#attached']['library'][] = 'locale/drupal.locale.admin'; $form['langcode'] = array('#type' => 'value', '#value' => $filter_values['langcode']); $form['strings'] = array('#type' => 'item', '#tree' => TRUE, '#language' => $langname, '#theme' => 'locale_translate_edit_form_strings'); if (isset($langcode)) { $strings = $this->translateFilterLoadStrings(); $plural_formulas = $this->state->get('locale.translation.plurals') ?: array(); foreach ($strings as $string) { // Cast into source string, will do for our purposes. $source = new SourceString($string); // Split source to work with plural values. $source_array = $source->getPlurals(); $translation_array = $string->getPlurals(); if (count($source_array) == 1) { // Add original string value and mark as non-plural. $form['strings'][$string->lid]['plural'] = array('#type' => 'value', '#value' => 0); $form['strings'][$string->lid]['original'] = array('#type' => 'item', '#title' => $this->t('Source string (@language)', array('@language' => $this->t('Built-in English'))), '#title_display' => 'invisible', '#markup' => '<span lang="en">' . String::checkPlain($source_array[0]) . '</span>'); } else { // Add original string value and mark as plural. $form['strings'][$string->lid]['plural'] = array('#type' => 'value', '#value' => 1); $form['strings'][$string->lid]['original_singular'] = array('#type' => 'item', '#title' => $this->t('Singular form'), '#markup' => '<span lang="en">' . String::checkPlain($source_array[0]) . '</span>', '#prefix' => '<span class="visually-hidden">' . $this->t('Source string (@language)', array('@language' => $this->t('Built-in English'))) . '</span>'); $form['strings'][$string->lid]['original_plural'] = array('#type' => 'item', '#title' => $this->t('Plural form'), '#markup' => '<span lang="en">' . String::checkPlain($source_array[1]) . '</span>'); } if (!empty($string->context)) { $form['strings'][$string->lid]['context'] = array('#type' => 'value', '#value' => '<span lang="en">' . String::checkPlain($string->context) . '</span>'); } // Approximate the number of rows to use in the default textarea. $rows = min(ceil(str_word_count($source_array[0]) / 12), 10); if (empty($form['strings'][$string->lid]['plural']['#value'])) { $form['strings'][$string->lid]['translations'][0] = array('#type' => 'textarea', '#title' => $this->t('Translated string (@language)', array('@language' => $langname)), '#title_display' => 'invisible', '#rows' => $rows, '#default_value' => $translation_array[0], '#attributes' => array('lang' => $langcode)); } else { // Dealing with plural strings. if (isset($plural_formulas[$langcode]['plurals']) && $plural_formulas[$langcode]['plurals'] > 2) { // Add a textarea for each plural variant. for ($i = 0; $i < $plural_formulas[$langcode]['plurals']; $i++) { $form['strings'][$string->lid]['translations'][$i] = array('#type' => 'textarea', '#title' => $i == 0 ? $this->t('Singular form') : format_plural($i, 'First plural form', '@count. plural form'), '#rows' => $rows, '#default_value' => isset($translation_array[$i]) ? $translation_array[$i] : '', '#attributes' => array('lang' => $langcode), '#prefix' => $i == 0 ? '<span class="visually-hidden">' . $this->t('Translated string (@language)', array('@language' => $langname)) . '</span>' : ''); } } else { // Fallback for unknown number of plurals. $form['strings'][$string->lid]['translations'][0] = array('#type' => 'textarea', '#title' => $this->t('Singular form'), '#rows' => $rows, '#default_value' => $translation_array[0], '#attributes' => array('lang' => $langcode), '#prefix' => '<span class="visually-hidden">' . $this->t('Translated string (@language)', array('@language' => $langname)) . '</span>'); $form['strings'][$string->lid]['translations'][1] = array('#type' => 'textarea', '#title' => $this->t('Plural form'), '#rows' => $rows, '#default_value' => isset($translation_array[1]) ? $translation_array[1] : '', '#attributes' => array('lang' => $langcode)); } } } if (count(Element::children($form['strings']))) { $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save translations')); } } return $form; }
/** * Implements \Symfony\Component\Translation\TranslatorInterface::transChoice(). */ public function transChoice($id, $number, array $parameters = array(), $domain = NULL, $locale = NULL) { // Violation messages can separated singular and plural versions by "|". $ids = explode('|', $id); if (!isset($ids[1])) { throw new \InvalidArgumentException(sprintf('The message "%s" cannot be pluralized, because it is missing a plural (e.g. "There is one apple|There are @count apples").', $id)); } return format_plural($number, $ids[0], $ids[1], $this->processParameters($parameters), $this->getOptions($domain, $locale)); }
function at_tf_admin_date_display_remaining($variables) { $remaining_days = $variables['remaining_days']; $output = ''; $show_remaining_text = t(' (Less than 1 day remaining!)'); if ($remaining_days) { $show_remaining_text = format_plural($remaining_days, ' (There is 1 day remaining!)', ' (There are @count days remaining.)'); } return '<span class="date-display-remaining">' . $show_remaining_text . '</span>'; }
/** * {@inheritdoc} */ public function getDescription() { $caption = ''; $num_links = $this->menuLinkManager->countMenuLinks($this->entity->id()); if ($num_links) { $caption .= '<p>' . format_plural($num_links, '<strong>Warning:</strong> There is currently 1 menu link in %title. It will be deleted (system-defined items will be reset).', '<strong>Warning:</strong> There are currently @count menu links in %title. They will be deleted (system-defined links will be reset).', array('%title' => $this->entity->label())) . '</p>'; } $caption .= '<p>' . t('This action cannot be undone.') . '</p>'; return $caption; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $num_nodes = $this->queryFactory->get('node')->condition('type', $this->entity->id())->count()->execute(); if ($num_nodes) { $caption = '<p>' . format_plural($num_nodes, '%type is used by 1 piece of content on your site. You can not remove this content type until you have removed all of the %type content.', '%type is used by @count pieces of content on your site. You may not remove %type until you have removed all of the %type content.', array('%type' => $this->entity->label())) . '</p>'; $form['#title'] = $this->getQuestion(); $form['description'] = array('#markup' => $caption); return $form; } return parent::buildForm($form, $form_state); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $blocks = $this->queryFactory->get('block_content')->condition('type', $this->entity->id())->execute(); if (!empty($blocks)) { $caption = '<p>' . format_plural(count($blocks), '%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', '%label is used by @count custom blocks on your site. You may not remove %label until you have removed all of the %label custom blocks.', array('%label' => $this->entity->label())) . '</p>'; $form['description'] = array('#markup' => $caption); return $form; } else { return parent::buildForm($form, $form_state); } }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $num_nodes = $this->database->query("SELECT COUNT(*) FROM {node} WHERE type = :type", array(':type' => $this->entity->id()))->fetchField(); if ($num_nodes) { $caption = '<p>' . format_plural($num_nodes, '%type is used by 1 piece of content on your site. You can not remove this content type until you have removed all of the %type content.', '%type is used by @count pieces of content on your site. You may not remove %type until you have removed all of the %type content.', array('%type' => $this->entity->label())) . '</p>'; $form['#title'] = $this->getQuestion(); $form['description'] = array('#markup' => $caption); return $form; } return parent::buildForm($form, $form_state); }
function mybasictheme_preprocess_node(&$variables) { // Check whether we have some comments present if (isset($variables['comment_count'])) { if ($variables['comment_count'] > 0) { // Add a new custom $commentlink variable $variables['commentlink'] = l(format_plural($variables['comment_count'], '1 comment', '@count comments'), drupal_lookup_path('alias', 'node/' . $variables['nid']), array('fragment' => 'comments')); } } // Re-write the $submitted variable the way we want it $variables['submitted'] = t('@datetime | by !username', array('!username' => $variables['name'], '@datetime' => date("j F Y", $variables['created']))); }
/** * Override or insert variables into the node template. */ function busy_preprocess_node(&$vars) { if ($vars['page'] && isset($vars['content']['links']['comment'])) { if (isset($vars['content']['links']['comment']['#links']['comment_add'])) { $vars['content']['links']['comment']['#links']['comments_count'] = $vars['content']['links']['comment']['#links']['comment_add']; } $vars['content']['links']['comment']['#links']['comments_count']['title'] = t('@num_comments', array('@num_comments' => format_plural($vars['comment_count'], '1 comment', '@count comments'))); $vars['content']['links']['comment']['#links']['comments_count']['attributes'] = array(); } if (theme_get_setting('toggle_node_user_picture', 'busy') && $vars['picture']) { $vars['classes_array'][] = 'node-with-author-picture'; } }
function mothership_preprocess_forum_list(&$variables) { global $user; $row = 0; $count = 0; $count2 = 0; // Sanitize each forum so that the template can safely print the data. foreach ($variables['forums'] as $id => $forum) { $variables['forums'][$id]->description = !empty($forum->description) ? filter_xss_admin($forum->description) : ''; $variables['forums'][$id]->link = url("forum/{$forum->tid}"); $variables['forums'][$id]->name = check_plain($forum->name); $variables['forums'][$id]->is_container = !empty($forum->container); $variables['forums'][$id]->zebra = $row % 2 == 0 ? 'odd' : 'even'; $row++; // $variables['forums'][$id]->depth == 1 // make a count of the non container forums if ($variables['forums'][$id]->depth) { if (!$variables['forums'][$id]->is_container) { $variables['forums'][$id]->count = $count; $count++; } } else { if (!$variables['forums'][$id]->is_container) { $variables['forums'][$id]->count = $count2; $count2++; } } $variables['forums'][$id]->new_text = ''; $variables['forums'][$id]->new_url = ''; $variables['forums'][$id]->new_topics = 0; $variables['forums'][$id]->old_topics = $forum->num_topics; $variables['forums'][$id]->icon_class = 'default'; $variables['forums'][$id]->icon_title = t('No new posts'); if ($user->uid) { $variables['forums'][$id]->new_topics = _forum_topics_unread($forum->tid, $user->uid); if ($variables['forums'][$id]->new_topics) { $variables['forums'][$id]->new_text = format_plural($variables['forums'][$id]->new_topics, '1 new', '@count new'); $variables['forums'][$id]->new_url = url("forum/{$forum->tid}", array('fragment' => 'new')); $variables['forums'][$id]->icon_class = 'new'; $variables['forums'][$id]->icon_title = t('New posts'); } $variables['forums'][$id]->old_topics = $forum->num_topics - $variables['forums'][$id]->new_topics; } $variables['forums'][$id]->last_reply = theme('forum_submitted', array('topic' => $forum->last_post)); } // $tid = term id. if (isset($variables['tid'])) { $variables['forum_id'] = $variables['tid']; unset($variables['tid']); } }
/** * Assert that a hook_file_* hook was called a certain number of times. * * @param $hook * String with the hook name, e.g. 'load', 'save', 'insert', etc. * @param $expected_count * Optional integer count. * @param $message * Optional translated string message. */ function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) { $actual_count = count(file_test_get_calls($hook)); if (!isset($message)) { if ($actual_count == $expected_count) { $message = format_string('hook_file_@name was called correctly.', array('@name' => $hook)); } elseif ($expected_count == 0) { $message = format_plural($actual_count, 'hook_file_@name was not expected to be called but was actually called once.', 'hook_file_@name was not expected to be called but was actually called @count times.', array('@name' => $hook, '@count' => $actual_count)); } else { $message = format_string('hook_file_@name was expected to be called %expected times but was called %actual times.', array('@name' => $hook, '%expected' => $expected_count, '%actual' => $actual_count)); } } $this->assertEqual($actual_count, $expected_count, $message); }
/** * Preprocessing the panel template. * * This is basically here to unify and clean up some class names. */ function ns_theme_preprocess_panels_pane(&$vars) { // Remove the old class. $vars['classes'] = strtr($vars['classes'], array('_' => '-')); // Adds the total number of comments to a node right next to the comment form title if ($vars['pane']->type == 'node_comment_form') { $comment_count = comment_num_all($vars['output']->delta); if ($comment_count > 0) { $title = '<span>' . $vars['output']->title . '</span><span class="total-comment-count">('; $title .= t('Total !comments', array('!comments' => format_plural($comment_count, '1 comment', '@count comments'))); $title .= ")</span>"; $vars['title'] = $title; } } }
function phptemplate_preprocess(&$vars, $hook) { global $theme; // Set Page Class $vars['page_class'] = theme_get_setting('page_class'); // Hide breadcrumb on all pages if (theme_get_setting('breadcrumb') == 0) { $vars['breadcrumb'] = ''; } $vars['closure'] .= ' <p id="theme-credit"><a href="http://drupal.org/project/strange_little_town">Strange Little Town</a> | ' . t('Original Designed : ') . '<a href="http://magical.nu/">Magical.nu</a> | ' . t('Drupal Ported : ') . '<a href="http://webzer.net/">Webzer.net</a></p> '; // Theme primary and secondary links. $vars['primary_menu'] = theme('links', $vars['primary_links'], array('class' => 'links primary-menu')); $vars['secondary_menu'] = theme('links', $vars['secondary_links'], array('class' => 'links secondary-menu')); // Set Accessibility nav bar if ($vars['primary_menu'] != '') { $vars['nav_access'] = ' <ul id="nav-access" class="hidden"> <li><a href="#primary-menu" accesskey="N" title="' . t('Skip to Primary Menu') . '">' . t('Skip to Primary Menu') . '</a></li> <li><a href="#main-content" accesskey="M" title="' . t('Skip to Main Content') . '">' . t('Skip to Main Content') . '</a></li> </ul> '; } else { $vars['nav_access'] = ' <ul id="nav-access" class="hidden"> <li><a href="#main-content" accesskey="M" title="' . t('Skip to Main Content') . '">' . t('Skip to Main Content') . '</a></li> </ul> '; } // Set Back to Top link toggle $vars['to_top'] = theme_get_setting('totop'); if (theme_get_setting('totop') == 0) { $vars['to_top'] = ''; } else { $vars['to_top'] = '<p id="to-top"><a href="#page">' . t('Back To Top') . '</a></p>'; } // Comments count if (isset($vars['node']->links['comment_comments'])) { if ($vars['teaser']) { $all = comment_num_all($vars['node']->nid); $vars['comments_count'] = format_plural($all, '1 comment', '@count comments'); } } // Make sure framework styles are placed above all others. $vars['css_alt'] = css_reorder($vars['css']); $vars['styles'] = drupal_get_css($vars['css_alt']); }
/** * {@inheritdoc} */ public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) { $singular = null; $plural = null; $forms = explode('|', $id); foreach ($forms as $form) { if (false !== strpos($form, '{1}')) { $singular = str_replace('{1}', '@count', $form); } if (false !== strpos($form, 'Inf[')) { $plural = preg_replace('/\\]\\d+,Inf\\[/', '@count', $form); } } $parameters['@count'] = $number; return format_plural($number, $singular, $plural, $parameters, ['context' => $domain, 'langcode' => $locale]); }
public function transChoice($message, $count, array $arguments = array(), $domain = null, $locale = null) { $singular = null; $plural = null; $forms = explode('|', $message); foreach ($forms as $form) { if (false !== strpos($form, '{1}')) { $singular = str_replace('{1}', '@count', $form); } if (false !== strpos($form, 'Inf[')) { $plural = preg_replace('/\\]\\d+,Inf\\[/', '@count', $form); } } $arguments['@count'] = $count; return format_plural($count, $singular, $plural, $arguments, ['context' => $domain, 'langcode' => $locale]); }
function bootstrap_theme_collection_contributions_form_submit(&$form, &$form_state) { $contribution_ids = $form_state['values']['table']; $deleted_cnt = 0; foreach ($contribution_ids as $contributor_id) { if (empty($contributor_id)) { continue; } $contribution = node_load($contributor_id); unset($contribution->field_cnob_collections[$contribution->language][0]); unset($contribution->og_group_ref[$contribution->language][0]); node_save($contribution); //node_delete($contributor_id); $deleted_cnt++; } drupal_set_message(format_plural($deleted_cnt, 'Deleted 1 contribution.', 'Deleted @count contributions.')); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // Find out how many users are directly assigned to this shortcut set, and // make a message. $number = $this->storage->countAssignedUsers($this->entity); $info = ''; if ($number) { $info .= '<p>' . format_plural($number, '1 user has chosen or been assigned to this shortcut set.', '@count users have chosen or been assigned to this shortcut set.') . '</p>'; } // Also, if a module implements hook_shortcut_default_set(), it's possible // that this set is being used as a default set. Add a message about that too. if ($this->moduleHandler->getImplementations('shortcut_default_set')) { $info .= '<p>' . t('If you have chosen this shortcut set as the default for some or all users, they may also be affected by deleting it.') . '</p>'; } $form['info'] = array('#markup' => $info); return parent::buildForm($form, $form_state); }
/** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items) { $elements = array(); $settings = $this->getFieldSettings(); foreach ($items as $delta => $item) { $output = $this->numberFormat($item->value); // Account for prefix and suffix. if ($this->getSetting('prefix_suffix')) { $prefixes = isset($settings['prefix']) ? array_map('field_filter_xss', explode('|', $settings['prefix'])) : array(''); $suffixes = isset($settings['suffix']) ? array_map('field_filter_xss', explode('|', $settings['suffix'])) : array(''); $prefix = count($prefixes) > 1 ? format_plural($item->value, $prefixes[0], $prefixes[1]) : $prefixes[0]; $suffix = count($suffixes) > 1 ? format_plural($item->value, $suffixes[0], $suffixes[1]) : $suffixes[0]; $output = $prefix . $output . $suffix; } $elements[$delta] = array('#markup' => $output); } return $elements; }
/** * Provides a string representation of how far apart two times are. * @param {int} $timeInterval [in positive seconds] * @param {int} $granularity [number of units to show before truncating] */ function format_interval($timeInterval, $granularity = 2) { if ($timeInterval < 0) { error_log("format_interval was passed a negative time inteval: {$timeInterval}, and returned 0 sec"); return "0 sec"; } $units = array('1 year|years' => 31536000, '1 week|weeks' => 604800, '1 day|days' => 86400, '1 hr|hrs' => 3600, '1 min|min' => 60, '1 sec|sec' => 1); $output = ''; foreach ($units as $key => $value) { $key = explode('|', $key); if ($timeInterval >= $value) { $output .= ($output ? ' ' : '') . format_plural(floor($timeInterval / $value), $key[0], $key[1]); $timeInterval %= $value; $granularity--; } if ($granularity == 0) { break; } } return $output ? $output : "0 sec"; }
/** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items) { $elements = array(); $settings = $this->getFieldSettings(); foreach ($items as $delta => $item) { $output = $this->numberFormat($item->value); // Account for prefix and suffix. if ($this->getSetting('prefix_suffix')) { $prefixes = isset($settings['prefix']) ? array_map(array($this, 'fieldFilterXss'), explode('|', $settings['prefix'])) : array(''); $suffixes = isset($settings['suffix']) ? array_map(array($this, 'fieldFilterXss'), explode('|', $settings['suffix'])) : array(''); $prefix = count($prefixes) > 1 ? format_plural($item->value, $prefixes[0], $prefixes[1]) : $prefixes[0]; $suffix = count($suffixes) > 1 ? format_plural($item->value, $suffixes[0], $suffixes[1]) : $suffixes[0]; $output = $prefix . $output . $suffix; } // Output the raw value in a content attribute if the text of the HTML // element differs from the raw value (for example when a prefix is used). if (!empty($item->_attributes) && $item->value != $output) { $item->_attributes += array('content' => $item->value); } $elements[$delta] = array('#markup' => $output); } return $elements; }
/** * Implements hook_preprocess_node(). */ function ctsibamboo_preprocess_node(&$vars) { global $user; $node = $vars['node']; if (!empty($vars['content']['links'])) { foreach ($vars['content']['links'] as $group => &$links) { switch ($group) { case 'comment': if ($node->comment != COMMENT_NODE_HIDDEN) { if (empty($links['#links']['comment-add']) and $node->comment == COMMENT_NODE_OPEN and user_access('post comments') and ($user->uid or variable_get('ctsi_allow_anonymous_comments_' . $node->type, 0))) { $links['#links']['comment-add'] = array('title' => t('Add new comment'), 'href' => "comment/reply/{$node->nid}", 'attributes' => array('title' => t('Add a new comment to this page.')), 'fragment' => 'comment-form'); } if (empty($links['#links']['comment-comments'])) { $links['#links']['comment-comments'] = array('title' => empty($node->comment_count) ? 'No comments yet' : format_plural($node->comment_count, '1 comment', '@count comments'), 'href' => "node/{$node->nid}", 'attributes' => array('title' => t('Jump to the first comment of this posting.')), 'fragment' => 'comments', 'html' => TRUE); } } break; } } } // Show only the username in submitted, the date is handled by node.tpl.php. $vars['submitted'] = t('Submitted by !username', array('!username' => ctsi_username_link($node))); }
/** * {@inheritdoc} */ public function parse($filename) { if (!isset(static::$parsedInfos[$filename])) { if (!file_exists($filename)) { static::$parsedInfos[$filename] = array(); } else { try { static::$parsedInfos[$filename] = Yaml::decode(file_get_contents($filename)); } catch (InvalidDataTypeException $e) { $message = String::format("Unable to parse !file: !error", array('!file' => $filename, '!error' => $e->getMessage())); throw new InfoParserException($message); } $missing_keys = array_diff($this->getRequiredKeys(), array_keys(static::$parsedInfos[$filename])); if (!empty($missing_keys)) { $message = format_plural(count($missing_keys), 'Missing required key (!missing_keys) in !file.', 'Missing required keys (!missing_keys) in !file.', array('!missing_keys' => implode(', ', $missing_keys), '!file' => $filename)); throw new InfoParserException($message); } if (isset(static::$parsedInfos[$filename]['version']) && static::$parsedInfos[$filename]['version'] === 'VERSION') { static::$parsedInfos[$filename]['version'] = \Drupal::VERSION; } } } return static::$parsedInfos[$filename]; }
function bootstrap_theme_messages_list_form_submit(&$form, &$form_state) { global $user; $message_ids = $form_state['values']['table']; $action = $form_state['values']['action']; $deleted_cnt = 0; foreach ($message_ids as $message_id) { if (empty($message_id)) { continue; } if ($action == 'remove') { //privatemsg_message_change_delete($message_id, 1); $delete_value = REQUEST_TIME; $update = db_update('pm_index')->fields(array('deleted' => $delete_value))->condition('mid', $pmid)->condition('recipient', $user->uid); } else { if ($action == 'blocking-user') { foreach (privatemsg_sql_participants($message_id)->execute() as $participant) { } } } $deleted_cnt++; } drupal_set_message(format_plural($deleted_cnt, 'Deleted 1 message.', 'Deleted @count messages.')); }
/** * {@inheritdoc} */ public function render(ResultRow $values) { $value = $this->getValue($values); if (!empty($this->options['set_precision'])) { $value = number_format($value, $this->options['precision'], $this->options['decimal'], $this->options['separator']); } else { $remainder = abs($value) - intval(abs($value)); $value = $value > 0 ? floor($value) : ceil($value); $value = number_format($value, 0, '', $this->options['separator']); if ($remainder) { // The substr may not be locale safe. $value .= $this->options['decimal'] . substr($remainder, 2); } } // Check to see if hiding should happen before adding prefix and suffix. if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) { return ''; } // Should we format as a plural. if (!empty($this->options['format_plural'])) { $value = format_plural($value, $this->options['format_plural_singular'], $this->options['format_plural_plural']); } return $this->sanitizeValue($this->options['prefix'], 'xss') . $this->sanitizeValue($value) . $this->sanitizeValue($this->options['suffix'], 'xss'); }
function neb_system_modules_uninstall($variables) { $form = $variables['form']; // No theming for the confirm form. if (isset($form['confirm'])) { return drupal_render($form); } // Table headers. $header = array(t('Uninstall'), t('Name'), t('Description')); // Display table. $rows = array(); foreach (element_children($form['modules']) as $module) { if (!empty($form['modules'][$module]['#required_by'])) { $disabled_message = format_plural(count($form['modules'][$module]['#required_by']), 'To uninstall @module, the following module must be uninstalled first: @required_modules', 'To uninstall @module, the following modules must be uninstalled first: @required_modules', array('@module' => $form['modules'][$module]['#module_name'], '@required_modules' => implode(', ', $form['modules'][$module]['#required_by']))); $disabled_message = '<div class="error warning admin-requirements">' . $disabled_message . '</div>'; } else { $disabled_message = ''; } $rows[] = array(array('data' => drupal_render($form['uninstall'][$module]), 'align' => 'center'), '<label for="' . $form['uninstall'][$module]['#id'] . '">' . drupal_render($form['modules'][$module]['name']) . '</label>', array('data' => drupal_render($form['modules'][$module]['description']) . $disabled_message, 'class' => array('description'))); } $output = theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No modules are available to uninstall.'))); $output .= drupal_render_children($form); return $output; }