本文整理汇总了PHP中drupal_get_messages函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_get_messages函数的具体用法?PHP drupal_get_messages怎么用?PHP drupal_get_messages使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drupal_get_messages函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: foundation_status_messages
/**
* Override theme_status_messages()
**/
function foundation_status_messages($variables)
{
$display = $variables['display'];
$output = '';
$status_heading = array('status' => t('Status message'), 'error' => t('Error message'), 'warning' => t('Warning message'));
foreach (drupal_get_messages($display) as $type => $messages) {
//convert to foundation classes
switch ($type) {
case 'error':
$type = 'alert';
break;
case 'status':
$type = 'success';
break;
case 'warning':
$type = 'secondary';
break;
}
$output .= "<div data-alert class=\"alert-box {$type}\">\n";
if (!empty($status_heading[$type])) {
$output .= '<h2 class="element-invisible">' . $status_heading[$type] . "</h2>\n";
}
if (count($messages) > 1) {
$output .= " <ul>\n";
foreach ($messages as $message) {
$output .= ' <li>' . $message . "</li>\n";
}
$output .= " </ul>\n";
} else {
$output .= $messages[0];
}
$output .= "<a href=\"\" class=\"close\">×</a></div>\n";
}
return $output;
}
示例2: aut_status_messages
function aut_status_messages($display = NULL)
{
$output = '';
foreach (drupal_get_messages($display) as $type => $messages) {
if ($type == "error") {
$alert = 'alert alert-error';
} elseif ($type == "status") {
$alert = 'alert alert-success';
} else {
$alert = 'alert';
}
$output .= "<div class=\"messages {$type} " . $alert . " \">\n";
if (count($messages) > 1) {
$output .= " <ul>\n";
foreach ($messages as $message) {
$output .= ' <li>' . $message . "</li>\n";
}
$output .= " </ul>\n";
} else {
$output .= $messages[0];
}
$output .= "</div>\n";
}
return $output;
}
示例3: bootstrap_status_messages
/**
* Returns HTML for status and/or error messages, grouped by type.
*
* An invisible heading identifies the messages for assistive technology.
* Sighted users see a colored box. See http://www.w3.org/TR/WCAG-TECHS/H69.html
* for info.
*
* @param array $variables
* An associative array containing:
* - display: (optional) Set to 'status' or 'error' to display only messages
* of that type.
*
* @return string
* The constructed HTML.
*
* @see theme_status_messages()
*
* @ingroup theme_functions
*/
function bootstrap_status_messages($variables)
{
$display = $variables['display'];
$output = '';
$status_heading = array('status' => t('Status message'), 'error' => t('Error message'), 'warning' => t('Warning message'), 'info' => t('Informative message'));
// Map Drupal message types to their corresponding Bootstrap classes.
// @see http://twitter.github.com/bootstrap/components.html#alerts
$status_class = array('status' => 'success', 'error' => 'danger', 'warning' => 'warning', 'info' => 'info');
// Retrieve messages.
$message_list = drupal_get_messages($display);
// Allow the disabled_messages module to filter the messages, if enabled.
if (module_exists('disable_messages') && variable_get('disable_messages_enable', '1')) {
$message_list = disable_messages_apply_filters($message_list);
}
foreach ($message_list as $type => $messages) {
$class = isset($status_class[$type]) ? ' alert-' . $status_class[$type] : '';
$output .= "<div class=\"alert alert-block{$class} messages {$type}\">\n";
$output .= " <a class=\"close\" data-dismiss=\"alert\" href=\"#\">×</a>\n";
if (!empty($status_heading[$type])) {
$output .= '<h4 class="element-invisible">' . _bootstrap_filter_xss($status_heading[$type]) . "</h4>\n";
}
if (count($messages) > 1) {
$output .= " <ul>\n";
foreach ($messages as $message) {
$output .= ' <li>' . _bootstrap_filter_xss($message) . "</li>\n";
}
$output .= " </ul>\n";
} else {
$output .= _bootstrap_filter_xss($messages[0]);
}
$output .= "</div>\n";
}
return $output;
}
示例4: bootstrap_status_messages
/**
* Overrides theme_status_messages().
*/
function bootstrap_status_messages($variables)
{
$display = $variables['display'];
$output = '';
$status_heading = array('status' => t('Status message'), 'error' => t('Error message'), 'warning' => t('Warning message'), 'info' => t('Informative message'));
// Map Drupal message types to their corresponding Bootstrap classes.
// @see http://twitter.github.com/bootstrap/components.html#alerts
$status_class = array('status' => 'success', 'error' => 'danger', 'warning' => 'warning', 'info' => 'info');
foreach (drupal_get_messages($display) as $type => $messages) {
$class = isset($status_class[$type]) ? ' alert-' . $status_class[$type] : '';
$output .= "<div class=\"alert alert-block{$class} messages {$type}\">\n";
$output .= " <a class=\"close\" data-dismiss=\"alert\" href=\"#\">×</a>\n";
if (!empty($status_heading[$type])) {
$output .= '<h4 class="element-invisible">' . $status_heading[$type] . "</h4>\n";
}
if (count($messages) > 1) {
$output .= " <ul>\n";
foreach ($messages as $message) {
$output .= ' <li>' . $message . "</li>\n";
}
$output .= " </ul>\n";
} else {
$output .= $messages[0];
}
$output .= "</div>\n";
}
return $output;
}
示例5: da_vinci_status_messages
/**
* Implements da_vinci_status_messages().
*/
function da_vinci_status_messages($variables)
{
$display = $variables['display'];
$output = '';
$status_heading = array('status' => t('Status message'), 'error' => t('Error message'), 'warning' => t('Warning message'));
foreach (drupal_get_messages($display) as $type => $messages) {
$output .= "<div class=\"messages {$type}\">\n";
$output .= "<div class=\"container\">\n";
if (!empty($status_heading[$type])) {
$output .= '<h2 class="element-invisible">' . $status_heading[$type] . "</h2>\n";
}
if (count($messages) > 1) {
$output .= " <ul>\n";
foreach ($messages as $message) {
$output .= ' <li>' . $message . "</li>\n";
}
$output .= " </ul>\n";
} else {
$output .= '<span>' . $messages[0] . '</span>';
}
$output .= "</div>\n";
$output .= "</div>\n";
}
return $output;
}
示例6: blackberry_2016_status_messages
function blackberry_2016_status_messages($variables)
{
$display = $variables['display'];
$output = '';
$status_heading = array('status' => t('Status message'), 'error' => t('Error message'), 'warning' => t('Warning message'));
foreach (drupal_get_messages($display) as $type => $messages) {
// skip all error/warning messages for anonymous users
if (!user_is_logged_in() && $type == 'PHP') {
} else {
$output .= '<div class="alert alert-block alert-' . $type . '"><div class="container"><div class="row"><div class="col-xs-12">';
if (!empty($status_heading[$type])) {
$output .= '<h2 class="element-invisible">' . $status_heading[$type] . '</h2>';
}
if (count($messages) > 1) {
$output .= '<ul>';
foreach ($messages as $message) {
$output .= ' <li>' . $message . '</li>';
}
$output .= '</ul>';
} else {
$output .= $messages[0];
}
$output .= '</div></div></div><a class="close" data-dismiss="alert" href="#">×</a></div>';
}
}
return $output;
}
示例7: magnetto_status_messages
function magnetto_status_messages(&$variables)
{
$display = $variables['display'];
$output = '';
$status_heading = array('status' => t('Status message'), 'error' => t('Error message'), 'warning' => t('Warning message'));
foreach (drupal_get_messages($display) as $type => $messages) {
$m_class = $type;
if ($type == 'status') {
$m_class = 'success';
}
$output .= "<div class=\"messages general_info_box {$m_class}\">\n";
if (!empty($status_heading[$type])) {
$output .= '<a class="close" href="#">Close</a><h2 class="element-invisible">' . $status_heading[$type] . "</h2>\n";
}
if (count($messages) > 1) {
$output .= " <ul>\n";
foreach ($messages as $message) {
$output .= ' <li>' . $message . "</li>\n";
}
$output .= " </ul>\n";
} else {
$output .= $messages[0];
}
$output .= "</div>\n";
}
return $output;
}
示例8: save
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state)
{
$field_collection_item = $this->getEntity();
if ($field_collection_item->isNew()) {
$host = $this->entityTypeManager->getStorage($this->getRequest()->get('host_type'))->load($this->getRequest()->get('host_id'));
$field_collection_item->setHostEntity($host);
$field_collection_item->save();
$host->save();
$messages = drupal_get_messages(NULL, false);
if (!isset($messages['warning']) && !isset($messages['error'])) {
drupal_set_message(t('Successfully added a @type.', array('@type' => $field_collection_item->bundle())));
}
} else {
$messages = drupal_get_messages(NULL, false);
if (!isset($messages['warning']) && !isset($messages['error'])) {
$field_collection_item->save();
drupal_set_message(t('Successfully edited %label.', array('%label' => $field_collection_item->label())));
}
}
if ($field_collection_item->id()) {
$form_state->setValue('id', $field_collection_item->id());
$form_state->set('id', $field_collection_item->id());
} else {
// In the unlikely case something went wrong on save, the block will be
// rebuilt and block form redisplayed.
drupal_set_message(t('The field collection item could not be saved.'), 'error');
$form_state->setRebuild();
}
/*
$form_state->setRedirect(
'field_collection_item.view',
array('field_collection_item' => $field_collection_item->id()
));
*/
}
示例9: hook_status_messages
function hook_status_messages($variables)
{
$display = $variables['display'];
$output = '';
$status_heading = array('status' => t('Status message'), 'error' => t('Error message'), 'warning' => t('Warning message'), 'info' => 'Status message');
$foundation_css = array('error' => 'warning', 'status' => 'info', 'warning' => 'warning');
foreach (drupal_get_messages($display) as $type => $messages) {
$output .= "<div data-alert class=\"alert-box {$foundation_css[$type]}\">\n";
if (!empty($status_heading[$type])) {
$output .= '<h2 class="element-invisible">' . $status_heading[$type] . "</h2>\n";
}
if (count($messages) > 1) {
$output .= " <ul>\n";
foreach ($messages as $message) {
$output .= ' <li>' . $message . "</li>\n";
}
$output .= " </ul>\n";
} else {
$output .= $messages[0];
}
$output .= '<a href="#" class="close">×</a>';
$output .= "</div>\n";
}
return $output;
}
示例10: testDrupalSetMessage
/**
* The basic functionality of drupal_set_message().
*/
public function testDrupalSetMessage()
{
drupal_set_message(t('A message: @foo', ['@foo' => 'bar']));
$messages = drupal_get_messages();
$this->assertInstanceOf('Drupal\\Core\\Render\\Markup', $messages['status'][0]);
$this->assertEquals('A message: bar', (string) $messages['status'][0]);
}
示例11: testMunging
/**
* Create a file and munge/unmunge the name.
*/
function testMunging()
{
// Disable insecure uploads.
\Drupal::config('system.file')->set('allow_insecure_uploads', 0)->save();
$munged_name = file_munge_filename($this->name, '', TRUE);
$messages = drupal_get_messages();
$this->assertTrue(in_array(t('For security reasons, your upload has been renamed to %filename.', array('%filename' => $munged_name)), $messages['status']), 'Alert properly set when a file is renamed.');
$this->assertNotEqual($munged_name, $this->name, format_string('The new filename (%munged) has been modified from the original (%original)', array('%munged' => $munged_name, '%original' => $this->name)));
}
示例12: testLegacyDrupal7
public function testLegacyDrupal7()
{
/** @var \Drupal\service_container\Legacy\Drupal7 $drupal7_service */
$drupal7_service = $this->container->get('drupal7');
$this->assertTrue($drupal7_service instanceof Drupal7);
$random_message = $this->randomString();
$drupal7_service->drupal_set_message($random_message, 'warning');
$messages = drupal_get_messages();
$this->assertTrue(in_array($random_message, $messages['warning']));
}
示例13: testDefaultComponents
/**
* Tests Rules default components.
*/
public function testDefaultComponents()
{
$config_entity = $this->storage->load('rules_test_default_component');
$user = $this->entityTypeManager->getStorage('user')->create(['mail' => 'test@example.com']);
$config_entity->getComponent()->setContextValue('user', $user)->execute();
// Test that the action was executed correctly.
$messages = drupal_get_messages();
$message_string = isset($messages['status'][0]) ? (string) $messages['status'][0] : NULL;
$this->assertEquals($message_string, 'test@example.com');
}
示例14: renderMessages
/**
* #post_render_cache callback; replaces placeholder with messages.
*
* Note: this is designed to replace all #post_render_cache placeholders for
* messages in a single #post_render_cache callback; hence all placeholders
* must be identical.
*
* @see ::getInfo()
*
* @param array $element
* The renderable array that contains the to be replaced placeholder.
* @param array $context
* An array with any context information.
*
* @return array
* A renderable array containing the messages.
*/
public static function renderMessages(array $element, array $context)
{
$renderer = static::renderer();
// Render the messages.
$messages = ['#theme' => 'status_messages', '#message_list' => drupal_get_messages($context['display']), '#status_headings' => ['status' => t('Status message'), 'error' => t('Error message'), 'warning' => t('Warning message')]];
$markup = $renderer->render($messages);
// Replace the placeholder.
$callback = get_class() . '::renderMessages';
$placeholder = $renderer->generateCachePlaceholder($callback, $context);
$element['#markup'] = str_replace($placeholder, $markup, $element['#markup']);
$element = $renderer->mergeBubbleableMetadata($element, $messages);
return $element;
}
示例15: processRequest
/**
* Processing the API request.
*/
public function processRequest(Request $request, RouteMatchInterface $route_match, $service_endpoint_id, $service_definition_id)
{
/** @var $service_endpoint \Drupal\services\ServiceEndpointInterface */
$service_endpoint = $this->entityManager()->getStorage('service_endpoint')->load($service_endpoint_id);
//TODO - pull in settings from service API and alter response
/** @var $service_def \Drupal\services\ServiceDefinitionInterface */
$service_def = $this->serviceDefinitionManager->createInstance($service_definition_id, []);
/**
* Iterate over any contexts defined for this plugin and extract them from
* the request defaults if the naming is identical. This means that a
* context named 'node' would match to a url parameter {node} or a route
* default named 'node'.
*/
foreach ($service_def->getContextDefinitions() as $context_id => $context_definition) {
if ($request->attributes->has($context_id)) {
$context = new Context($context_definition, $request->attributes->get($context_id));
$service_def->setContext($context_id, $context);
}
}
// Get the data from the plugin.
$data = $service_def->processRequest($request, $route_match, $this->serializer);
$code = $service_def->getPluginDefinition()['response_code'];
$headers = [];
$messages = drupal_get_messages();
if ($messages) {
foreach ($messages as $type => $type_message) {
$headers["X-Drupal-Services-Messages-{$type}"] = implode("; ", $type_message);
}
}
// Find the request format to determin how we're going to serialize this data
$format = $request->getRequestFormat();
$data = $this->serializer->serialize($data, $format);
/**
* Create a new Cacheable Response object with our serialized data, set its
* Content-Type to match the format of our Request and add the service
* definition plugin as a cacheable dependency.
*
* This last step will extract the cache context, tags and max-ages from
* any context the plugin required to operate.
*/
$response = new CacheableResponse($data, $code, $headers);
$response->headers->add(['Content-Type' => $request->getMimeType($format)]);
$response->addCacheableDependency($service_def);
// Be explicit about the caching needs of this response.
$response->setVary('Accept');
$service_def->processResponse($response);
return $response;
}