本文整理汇总了PHP中drupal_process_attached函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_process_attached函数的具体用法?PHP drupal_process_attached怎么用?PHP drupal_process_attached使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drupal_process_attached函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ajaxRemove
/**
* Ajax callback to remove a field collection from a multi-valued field.
*
* @param array $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An AjaxResponse object.
*/
function ajaxRemove(array $form, FormStateInterface &$form_state)
{
// Process user input. $form and $form_state are modified in the process.
//\Drupal::formBuilder()->processForm($form['#form_id'], $form, $form_state);
// Retrieve the element to be rendered.
$trigger = $form_state->getTriggeringElement();
$form_parents = explode('/', $trigger['#ajax']['options']['query']['element_parents']);
$address = array_slice($form_parents, 0, -1);
$form = NestedArray::getValue($form, $address);
$status_messages = array('#theme' => 'status_messages');
$renderer = \Drupal::service('renderer');
$form['#prefix'] = empty($form['#prefix']) ? $renderer->render($status_messages) : $form['#prefix'] . $renderer->render($status_messages);
$output = $renderer->render($form);
drupal_process_attached($form);
// TODO: Preserve javascript. See https://www.drupal.org/node/2502743 .
$response = new AjaxResponse();
return $response->addCommand(new ReplaceCommand(NULL, $output));
}
示例2: render
/**
* {@inheritdoc}
*/
public function render(array $render_array)
{
$content = $this->drupalRenderRoot($render_array);
if (!empty($render_array)) {
drupal_process_attached($render_array);
}
$cache = !empty($render_array['#cache']['tags']) ? ['tags' => $render_array['#cache']['tags']] : [];
$fragment = new HtmlFragment($content, $cache);
if (isset($render_array['#title'])) {
$fragment->setTitle($render_array['#title'], Title::FILTER_XSS_ADMIN);
}
$attached = isset($render_array['#attached']) ? $render_array['#attached'] : [];
$attached += ['feed' => [], 'html_head' => [], 'html_head_link' => []];
// Add feed links from the page content.
foreach ($attached['feed'] as $feed) {
$fragment->addLinkElement(new FeedLinkElement($feed[1], $this->urlGenerator->generateFromPath($feed[0])));
}
// Add generic links from the page content.
foreach ($attached['html_head_link'] as $link) {
$fragment->addLinkElement(new LinkElement($this->urlGenerator->generateFromPath($link[0]['href']), $link[0]['rel']));
}
// @todo Also transfer the contents of "_drupal_add_html_head" once
// https://www.drupal.org/node/2296951 lands.
// @todo Transfer CSS and JS over to the fragment once those are supported
// on the fragment object.
return $fragment;
}
示例3: testLibraryInfoAlter
/**
* Verifies that the datepicker can be localized.
*
* @see locale_library_info_alter()
*/
public function testLibraryInfoAlter()
{
$attached['#attached']['library'][] = 'core/jquery.ui.datepicker';
drupal_render($attached);
drupal_process_attached($attached);
$scripts = drupal_get_js();
$this->assertTrue(strpos($scripts, 'locale.datepicker.js'), 'locale.datepicker.js added to scripts.');
}
示例4: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
if ($form_state->getValue('add_files')) {
$path = drupal_get_path('module', 'system');
$attached = array('#attached' => array('css' => array($path . '/css/system.admin.css' => array()), 'js' => array(0 => array('type' => 'setting', 'data' => array('ajax_forms_test_lazy_load_form_submit' => 'executed')), $path . '/system.js' => array())));
drupal_render($attached);
drupal_process_attached($attached);
}
$form_state->setRebuild();
}
示例5: testDrupalProcessAttached
/**
* Tests drupal_process_attached().
*/
public function testDrupalProcessAttached()
{
// Specify invalid attachments in a render array.
$build['#attached']['library'][] = 'core/drupal.states';
$build['#attached']['drupal_process_states'][] = [];
try {
drupal_process_attached($build);
$this->fail("Invalid #attachment 'drupal_process_states' allowed");
} catch (\Exception $e) {
$this->pass("Invalid #attachment 'drupal_process_states' not allowed");
}
}
示例6: build
/**
* {@inheritdoc}
*/
public function build()
{
// Grab test attachment fixtures from
// Drupal\render_attached_test\Controller\TestController.
$controller = new TestController();
$attached = BubbleableMetadata::mergeAttachments($controller->feed(), $controller->head());
$attached = BubbleableMetadata::mergeAttachments($attached, $controller->header());
$attached = BubbleableMetadata::mergeAttachments($attached, $controller->teapotHeaderStatus());
// Use drupal_process_attached() to attach all the #attached stuff.
drupal_process_attached($attached);
// Return some arbitrary markup so the block doesn't disappear.
return ['#markup' => 'Headers handled by drupal_process_attached().'];
}
示例7: upload
/**
* Processes AJAX file uploads and deletions.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* An AjaxResponse object.
*/
public function upload(Request $request)
{
$form_parents = explode('/', $request->query->get('element_parents'));
$form_build_id = $request->query->get('form_build_id');
$request_form_build_id = $request->request->get('form_build_id');
if (empty($request_form_build_id) || $form_build_id !== $request_form_build_id) {
// Invalid request.
drupal_set_message(t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', array('@size' => format_size(file_upload_max_size()))), 'error');
$response = new AjaxResponse();
$status_messages = array('#theme' => 'status_messages');
return $response->addCommand(new ReplaceCommand(NULL, drupal_render($status_messages)));
}
try {
/** @var $ajaxForm \Drupal\system\FileAjaxForm */
$ajaxForm = $this->getForm($request);
$form = $ajaxForm->getForm();
$form_state = $ajaxForm->getFormState();
$commands = $ajaxForm->getCommands();
} catch (HttpExceptionInterface $e) {
// Invalid form_build_id.
drupal_set_message(t('An unrecoverable error occurred. Use of this form has expired. Try reloading the page and submitting again.'), 'error');
$response = new AjaxResponse();
$status_messages = array('#theme' => 'status_messages');
return $response->addCommand(new ReplaceCommand(NULL, drupal_render($status_messages)));
}
// Get the current element and count the number of files.
$current_element = NestedArray::getValue($form, $form_parents);
$current_file_count = isset($current_element['#file_upload_delta']) ? $current_element['#file_upload_delta'] : 0;
// Process user input. $form and $form_state are modified in the process.
drupal_process_form($form['#form_id'], $form, $form_state);
// Retrieve the element to be rendered.
$form = NestedArray::getValue($form, $form_parents);
// Add the special Ajax class if a new file was added.
if (isset($form['#file_upload_delta']) && $current_file_count < $form['#file_upload_delta']) {
$form[$current_file_count]['#attributes']['class'][] = 'ajax-new-content';
} else {
$form['#suffix'] .= '<span class="ajax-new-content"></span>';
}
$status_messages = array('#theme' => 'status_messages');
$form['#prefix'] .= drupal_render($status_messages);
$output = drupal_render($form);
drupal_process_attached($form);
$js = _drupal_add_js();
$settings = drupal_merge_js_settings($js['settings']['data']);
$response = new AjaxResponse();
foreach ($commands as $command) {
$response->addCommand($command, TRUE);
}
return $response->addCommand(new ReplaceCommand(NULL, $output, $settings));
}
示例8: testBasicFeedAddNoTitle
/**
* Tests attaching feeds with paths, URLs, and titles.
*/
function testBasicFeedAddNoTitle()
{
$path = $this->randomMachineName(12);
$external_url = 'http://' . $this->randomMachineName(12) . '/' . $this->randomMachineName(12);
$fully_qualified_local_url = Url::fromUri('base:' . $this->randomMachineName(12), array('absolute' => TRUE))->toString();
$path_for_title = $this->randomMachineName(12);
$external_for_title = 'http://' . $this->randomMachineName(12) . '/' . $this->randomMachineName(12);
$fully_qualified_for_title = Url::fromUri('base:' . $this->randomMachineName(12), array('absolute' => TRUE))->toString();
$urls = array('path without title' => array('url' => Url::fromUri('base:' . $path, array('absolute' => TRUE))->toString(), 'title' => ''), 'external URL without title' => array('url' => $external_url, 'title' => ''), 'local URL without title' => array('url' => $fully_qualified_local_url, 'title' => ''), 'path with title' => array('url' => Url::fromUri('base:' . $path_for_title, array('absolute' => TRUE))->toString(), 'title' => $this->randomMachineName(12)), 'external URL with title' => array('url' => $external_for_title, 'title' => $this->randomMachineName(12)), 'local URL with title' => array('url' => $fully_qualified_for_title, 'title' => $this->randomMachineName(12)));
$build = [];
foreach ($urls as $feed_info) {
$build['#attached']['feed'][] = [$feed_info['url'], $feed_info['title']];
}
drupal_process_attached($build);
$this->setRawContent(drupal_get_html_head());
foreach ($urls as $description => $feed_info) {
$this->assertPattern($this->urlToRSSLinkPattern($feed_info['url'], $feed_info['title']), format_string('Found correct feed header for %description', array('%description' => $description)));
}
}
示例9: testOrder
/**
* Tests AjaxResponse::prepare() AJAX commands ordering.
*/
public function testOrder()
{
$path = drupal_get_path('module', 'system');
$expected_commands = array();
// Expected commands, in a very specific order.
$expected_commands[0] = new SettingsCommand(array('ajax' => 'test'), TRUE);
drupal_static_reset('_drupal_add_css');
$attached = array('#attached' => array('css' => array($path . '/css/system.admin.css' => array(), $path . '/css/system.maintenance.css' => array())));
drupal_render($attached);
drupal_process_attached($attached);
$expected_commands[1] = new AddCssCommand(drupal_get_css(_drupal_add_css(), TRUE));
drupal_static_reset('_drupal_add_js');
$attached = array('#attached' => array('js' => array($path . '/system.js' => array())));
drupal_render($attached);
drupal_process_attached($attached);
$expected_commands[2] = new PrependCommand('head', drupal_get_js('header', _drupal_add_js(), TRUE));
drupal_static_reset('_drupal_add_js');
$attached = array('#attached' => array('js' => array($path . '/system.modules.js' => array('scope' => 'footer'))));
drupal_render($attached);
drupal_process_attached($attached);
$expected_commands[3] = new AppendCommand('body', drupal_get_js('footer', _drupal_add_js(), TRUE));
$expected_commands[4] = new HtmlCommand('body', 'Hello, world!');
// Load any page with at least one CSS file, at least one JavaScript file
// and at least one #ajax-powered element. The latter is an assumption of
// drupalPostAjaxForm(), the two former are assumptions of
// AjaxReponse::ajaxRender().
// @todo refactor AJAX Framework + tests to make less assumptions.
$this->drupalGet('ajax_forms_test_lazy_load_form');
// Verify AJAX command order — this should always be the order:
// 1. JavaScript settings
// 2. CSS files
// 3. JavaScript files in the header
// 4. JavaScript files in the footer
// 5. Any other AJAX commands, in whatever order they were added.
$commands = $this->drupalPostAjaxForm(NULL, array(), NULL, 'ajax-test/order', array(), array(), NULL, array());
$this->assertCommand(array_slice($commands, 0, 1), $expected_commands[0]->render(), 'Settings command is first.');
$this->assertCommand(array_slice($commands, 1, 1), $expected_commands[1]->render(), 'CSS command is second (and CSS files are ordered correctly).');
$this->assertCommand(array_slice($commands, 2, 1), $expected_commands[2]->render(), 'Header JS command is third.');
$this->assertCommand(array_slice($commands, 3, 1), $expected_commands[3]->render(), 'Footer JS command is fourth.');
$this->assertCommand(array_slice($commands, 4, 1), $expected_commands[4]->render(), 'HTML command is fifth.');
}
示例10: render
/**
* {@inheritdoc}
*/
public function render(HtmlFragmentInterface $fragment, $status_code = 200)
{
// Converts the given HTML fragment which represents the main content region
// of the page into a render array.
$page_content['main'] = array('#markup' => $fragment->getContent());
$page_content['#title'] = $fragment->getTitle();
if ($fragment instanceof CacheableInterface) {
$page_content['main']['#cache']['tags'] = $fragment->getCacheTags();
}
// Build the full page array by calling drupal_prepare_page(), which invokes
// hook_page_build(). This adds the other regions to the page.
$page_array = drupal_prepare_page($page_content);
// Build the HtmlPage object.
$page = new HtmlPage('', array(), $fragment->getTitle());
$page = $this->preparePage($page, $page_array);
$page->setBodyTop(drupal_render($page_array['page_top']));
$page->setBodyBottom(drupal_render($page_array['page_bottom']));
$page->setContent(drupal_render($page_array));
$page->setStatusCode($status_code);
drupal_process_attached($page_array);
if (isset($page_array['page_top'])) {
drupal_process_attached($page_array['page_top']);
}
if (isset($page_array['page_bottom'])) {
drupal_process_attached($page_array['page_bottom']);
}
if ($fragment instanceof CacheableInterface) {
// Persist cache tags associated with this page. Also associate the
// "rendered" cache tag. This allows us to invalidate the entire render
// cache, regardless of the cache bin.
$cache_tags = $page_array['#cache']['tags'];
$cache_tags[] = 'rendered';
// Only keep unique cache tags. We need to prevent duplicates here already
// rather than only in the cache layer, because they are also used by
// reverse proxies (like Varnish), not only by Drupal's page cache.
$page->setCacheTags(array_unique($cache_tags));
}
return $page;
}
示例11: feedDpa
/**
* Test attached feed rendering as a side-effect.
*
* @return array
* A render array using the 'feed' directive.
*/
public function feedDpa()
{
drupal_process_attached($this->feed());
return ['#markup' => "I'm some markup here to fool the kernel into rendering this page."];
}
示例12: render
/**
* Renders a render array.
*
* @param array $elements
* The elements to render.
*
* @return string
* The rendered string output (typically HTML).
*/
protected function render(array &$elements)
{
$content = drupal_render($elements);
drupal_process_attached($elements);
$this->setRawContent($content);
$this->verbose('<pre style="white-space: pre-wrap">' . String::checkPlain($content));
return $content;
}
示例13: drupalRender
/**
* Wraps drupal_render.
*
* @param array $elements
* The structured array describing the data to be rendered.
*
* @return string
* The rendered HTML.
*
* @todo Remove once drupal_render is converted to autoloadable code.
* @see https://drupal.org/node/2171071
*/
protected function drupalRender(array $elements)
{
$output = drupal_render($elements);
drupal_process_attached($elements);
return $output;
}
示例14: attachments
/**
* Returns AJAX commands to load in-place editors' attachments.
*
* Given a list of in-place editor IDs as POST parameters, render AJAX
* commands to load those in-place editors.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* The Ajax response.
*/
public function attachments(Request $request)
{
$response = new AjaxResponse();
$editors = $request->request->get('editors');
if (!isset($editors)) {
throw new NotFoundHttpException();
}
$elements['#attached'] = $this->editorSelector->getEditorAttachments($editors);
drupal_process_attached($elements);
return $response;
}
示例15: processAttachments
/**
* {@inheritdoc}
*/
public function processAttachments(AttachmentsInterface $response)
{
// @todo Convert to assertion once https://www.drupal.org/node/2408013 lands
if (!$response instanceof HtmlResponse) {
throw new \InvalidArgumentException('\\Drupal\\Core\\Render\\HtmlResponse instance expected.');
}
// First, render the actual placeholders; this may cause additional
// attachments to be added to the response, which the attachment
// placeholders rendered by renderHtmlResponseAttachmentPlaceholders() will
// need to include.
$response = $this->renderPlaceholders($response);
$attached = $response->getAttachments();
// Get the placeholders from attached and then remove them.
$attachment_placeholders = $attached['html_response_attachment_placeholders'];
unset($attached['html_response_attachment_placeholders']);
$variables = $this->processAssetLibraries($attached, $attachment_placeholders);
// Handle all non-asset attachments. This populates drupal_get_html_head().
$all_attached = ['#attached' => $attached];
drupal_process_attached($all_attached);
// Get HTML head elements - if present.
if (isset($attachment_placeholders['head'])) {
$variables['head'] = drupal_get_html_head(FALSE);
}
// Now replace the attachment placeholders.
$this->renderHtmlResponseAttachmentPlaceholders($response, $attachment_placeholders, $variables);
// Finally set the headers on the response if any bubbled.
if (!empty($attached['http_header'])) {
$this->setHeaders($response, $attached['http_header']);
}
return $response;
}