本文整理汇总了PHP中Drupal\Core\Render\Element::getVisibleChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP Element::getVisibleChildren方法的具体用法?PHP Element::getVisibleChildren怎么用?PHP Element::getVisibleChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Render\Element
的用法示例。
在下文中一共展示了Element::getVisibleChildren方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: groupElements
/**
* Groups elements with the same #group so that they can be inlined.
*/
public static function groupElements(array $element)
{
$sort = [];
foreach (Element::getVisibleChildren($element) as $key) {
if (isset($element[$key]['#group'])) {
// Copy the element to the container and remove the original.
$group_index = $element[$key]['#group'];
$container_key = 'container' . $group_index;
$element[$container_key][$key] = $element[$key];
unset($element[$key]);
// Mark the container for sorting.
if (!in_array($container_key, $sort)) {
$sort[] = $container_key;
}
}
}
// Sort the moved elements, so that their #weight stays respected.
foreach ($sort as $key) {
uasort($element[$key], ['Drupal\\Component\\Utility\\SortArray', 'sortByWeightProperty']);
}
return $element;
}
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$config = $this->config('xmlsitemap.settings');
$intervals = array(300, 900, 1800, 3600, 10800, 21600, 43200, 86400, 172800, 259200, 604800);
$intervals = array_combine($intervals, $intervals);
$format_intervals = array();
foreach ($intervals as $key => $value) {
$format_intervals[$key] = $this->date->formatInterval($key);
}
$form['minimum_lifetime'] = array('#type' => 'select', '#title' => t('Minimum sitemap lifetime'), '#options' => array(0 => t('No minimum')) + $format_intervals, '#description' => t('The minimum amount of time that will elapse before the sitemaps are regenerated. The sitemaps will also only be regenerated on cron if any links have been added, updated, or deleted.') . '<br />' . t('Recommended value: %value.', array('%value' => t('1 day'))), '#default_value' => $config->get('minimum_lifetime'));
$form['xsl'] = array('#type' => 'checkbox', '#title' => t('Include a stylesheet in the sitemaps for humans.'), '#description' => t('When enabled, this will add formatting and tables with sorting to make it easier to view the XML sitemap data instead of viewing raw XML output. Search engines will ignore this.'), '#default_value' => $config->get('xsl'));
$form['prefetch_aliases'] = array('#type' => 'checkbox', '#title' => t('Prefetch URL aliases during sitemap generation.'), '#description' => t('When enabled, this will fetch all URL aliases at once instead of one at a time during sitemap generation. For medium or large sites, it is recommended to disable this feature as it uses a lot of memory.'), '#default_value' => $config->get('prefetch_aliases'));
$form['advanced'] = array('#type' => 'details', '#title' => t('Advanced settings'), '#collapsible' => TRUE, '#collapsed' => !$this->state->get('xmlsitemap_developer_mode'), '#weight' => 10);
$form['advanced']['gz'] = array('#type' => 'checkbox', '#title' => t('Generate additional compressed sitemaps using gzip.'), '#default_value' => $config->get('gz'), '#disabled' => !function_exists('gzencode'));
$chunk_sizes = array(100, 500, 1000, 2500, 5000, 10000, 25000, XMLSITEMAP_MAX_SITEMAP_LINKS);
$form['advanced']['chunk_size'] = array('#type' => 'select', '#title' => t('Number of links in each sitemap page'), '#options' => array('auto' => t('Automatic (recommended)')) + array_combine($chunk_sizes, $chunk_sizes), '#default_value' => xmlsitemap_var('chunk_size'), '#description' => t('If there are problems with rebuilding the sitemap, you may want to manually set this value. If you have more than @max links, an index with multiple sitemap pages will be generated. There is a maximum of @max sitemap pages.', array('@max' => XMLSITEMAP_MAX_SITEMAP_LINKS)));
$batch_limits = array(5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000);
$form['advanced']['batch_limit'] = array('#type' => 'select', '#title' => t('Maximum number of sitemap links to process at once'), '#options' => array_combine($batch_limits, $batch_limits), '#default_value' => xmlsitemap_var('batch_limit'), '#description' => t('If you have problems running cron or rebuilding the sitemap, you may want to lower this value.'));
if (!xmlsitemap_check_directory()) {
$form_state->setErrorByName('path', t('The directory %directory does not exist or is not writable.', array('%directory' => xmlsitemap_get_directory())));
}
$form['advanced']['path'] = array('#type' => 'textfield', '#title' => t('Sitemap cache directory'), '#default_value' => $config->get('path'), '#size' => 30, '#maxlength' => 255, '#description' => t('Subdirectory where the sitemap data will be stored. This folder <strong>must not be shared</strong> with any other Drupal site or install using XML sitemap.'), '#field_prefix' => file_build_uri(''), '#required' => TRUE);
$form['advanced']['xmlsitemap_base_url'] = array('#type' => 'textfield', '#title' => t('Default base URL'), '#default_value' => $this->state->get('xmlsitemap_base_url'), '#size' => 30, '#description' => t('This is the default base URL used for sitemaps and sitemap links.'), '#required' => TRUE);
$form['advanced']['lastmod_format'] = array('#type' => 'select', '#title' => t('Last modification date format'), '#options' => array(XMLSITEMAP_LASTMOD_SHORT => t('Short'), XMLSITEMAP_LASTMOD_MEDIUM => t('Medium'), XMLSITEMAP_LASTMOD_LONG => t('Long')), '#default_value' => $config->get('lastmod_format'));
foreach ($form['advanced']['lastmod_format']['#options'] as $key => &$label) {
$label .= ' (' . gmdate($key, REQUEST_TIME) . ')';
}
$form['advanced']['xmlsitemap_developer_mode'] = array('#type' => 'checkbox', '#title' => t('Enable developer mode to expose additional settings.'), '#default_value' => $this->state->get('xmlsitemap_developer_mode'));
$form['xmlsitemap_settings'] = array('#type' => 'vertical_tabs', '#weight' => 20);
$entities = xmlsitemap_get_link_info(NULL, TRUE);
foreach ($entities as $entity => $entity_info) {
$form[$entity] = array('#type' => 'details', '#title' => $entity_info['label'], '#collapsible' => TRUE, '#collapsed' => TRUE, '#group' => 'xmlsitemap_settings');
if (!empty($entity_info['bundles'])) {
// If this entity has bundles, show a bundle setting summary.
xmlsitemap_add_form_entity_summary($form[$entity], $entity, $entity_info);
}
if (!empty($entity_info['xmlsitemap']['settings callback'])) {
// Add any entity-specific settings.
$entity_info['xmlsitemap']['settings callback']($form[$entity]);
}
// Ensure that the entity fieldset is not shown if there are no accessible
// sub-elements.
$form[$entity]['#access'] = (bool) Element::getVisibleChildren($form[$entity]);
}
return parent::buildForm($form, $form_state);
}
示例3: removeFormWrapperRecursive
/**
* Removes the "form" theme wrapper from all nested elements of the given
* render array.
*
* @param array $content
* A render array that could potentially contain a nested form.
*
* @return array
* The potentially modified render array.
*/
protected function removeFormWrapperRecursive(array $content)
{
if (is_array($content)) {
// If this block is rendered as a form, we'll need to disable its wrapping
// element.
if (isset($content['#theme_wrappers']) && ($key = array_search('form', $content['#theme_wrappers'])) !== FALSE) {
unset($content['#theme_wrappers'][$key]);
}
// Perform the same operation on child elements.
foreach (Element::getVisibleChildren($content) as $key) {
$content[$key] = $this->removeFormWrapperRecursive($content[$key]);
}
}
return $content;
}
示例4: form
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state)
{
$form = parent::form($form, $form_state);
if ($this->entity->getContext() == NULL) {
$this->entity->context = array();
$this->entity->setOriginalId(NULL);
}
$xmlsitemap = $this->entity;
$form['#entity'] = $xmlsitemap;
$form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $xmlsitemap->label(), '#description' => $this->t('Label for the Example.'), '#required' => TRUE);
$form['context'] = array('#tree' => TRUE);
$visible_children = Element::getVisibleChildren($form['context']);
if (empty($visible_children)) {
$form['context']['empty'] = array('#type' => 'markup', '#markup' => '<p>' . t('There are currently no XML sitemap contexts available.') . '</p>');
}
return $form;
}
示例5: buildForm
/**
* Builds a form that configure an existing or new layout for the IPE.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param string $layout_id
* The requested Layout ID.
* @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display
* The current PageVariant ID.
*
* @return array
* The form structure.
*/
public function buildForm(array $form, FormStateInterface $form_state, $layout_id = NULL, PanelsDisplayVariant $panels_display = NULL)
{
// We require these default arguments.
if (!$layout_id || !$panels_display) {
return FALSE;
}
// Save the panels display for later.
$this->panelsDisplay = $panels_display;
// Check if this is the current layout, and if not create an instance.
$layout = $this->panelsDisplay->getLayout();
$current = $layout->getPluginId() == $layout_id;
if (!$current) {
// Create a new layout instance.
$layout = $this->layoutManager->createInstance($layout_id, []);
}
// Save the layout for future use.
$this->layout = $layout;
$form['settings'] = $layout->buildConfigurationForm([], $form_state);
$form['settings']['#tree'] = TRUE;
// If the form is empty, inform the user.
if (empty(Element::getVisibleChildren($form['settings']))) {
$form['settings'][] = ['#markup' => $this->t('<h5>This layout does not provide any configuration.</h5>')];
}
// Add an add button, which is only used by our App.
$form['submit'] = ['#type' => 'button', '#value' => $current ? $this->t('Update') : $this->t('Change Layout'), '#ajax' => ['callback' => '::submitForm', 'wrapper' => 'panels-ipe-layout-form-wrapper', 'method' => 'replace', 'progress' => ['type' => 'throbber', 'message' => '']]];
return $form;
}
示例6: actions
/**
* {@inheritdoc}
*/
protected function actions(array $form, FormStateInterface $form_state)
{
return array('submit' => array('#type' => 'submit', '#value' => t('Save changes'), '#access' => (bool) Element::getVisibleChildren($form['grade_letter_sets']['letters']), '#submit' => array('::submitForm', '::save')));
}
示例7: hideEmptyVisibilitySettings
/**
* Hides the visibility settings if the stores widget is a hidden element.
*
* @param array $form
* The form.
*
* @return array
* The modified visibility_settings element.
*/
public static function hideEmptyVisibilitySettings($form)
{
if (isset($form['stores']['widget']['target_id'])) {
$stores_element = $form['stores']['widget']['target_id'];
if (!Element::getVisibleChildren($stores_element)) {
$form['visibility_settings']['#printed'] = TRUE;
// Move the stores widget out of the visibility_settings group to
// ensure that its hidden element is still present in the HTML.
unset($form['stores']['#group']);
}
}
return $form;
}
示例8: actions
/**
* {@inheritdoc}
*/
protected function actions(array $form, array &$form_state)
{
// Only includes a Save action for the entity, no direct Delete button.
return array('submit' => array('#value' => t('Save changes'), '#access' => (bool) Element::getVisibleChildren($form['shortcuts']['links']), '#submit' => array(array($this, 'submit'), array($this, 'save'))));
}
示例9: preRenderDetails
/**
* Adds form element theming to details.
*
* @param $element
* An associative array containing the properties and children of the
* details.
*
* @return
* The modified element.
*/
public static function preRenderDetails($element)
{
Element::setAttributes($element, array('id'));
// The .js-form-wrapper class is required for #states to treat details like
// containers.
static::setAttributes($element, array('js-form-wrapper', 'form-wrapper'));
// Collapsible details.
$element['#attached']['library'][] = 'core/drupal.collapse';
if (!empty($element['#open'])) {
$element['#attributes']['open'] = 'open';
}
// Do not render optional details elements if there are no children.
if (isset($element['#parents'])) {
$group = implode('][', $element['#parents']);
if (!empty($element['#optional']) && !Element::getVisibleChildren($element['#groups'][$group])) {
$element['#printed'] = TRUE;
}
}
return $element;
}
示例10: build
/**
* {@inheritdoc}
*/
public function build()
{
$config = $this->configuration;
$cacheability = new CacheableMetadata();
$tabs = ['#theme' => 'menu_local_tasks'];
// Add only selected levels for the printed output.
if ($config['primary']) {
$links = $this->localTaskManager->getLocalTasks($this->routeMatch->getRouteName(), 0);
$cacheability = $cacheability->merge($links['cacheability']);
// Do not display single tabs.
$tabs += ['#primary' => count(Element::getVisibleChildren($links['tabs'])) > 1 ? $links['tabs'] : []];
}
if ($config['secondary']) {
$links = $this->localTaskManager->getLocalTasks($this->routeMatch->getRouteName(), 1);
$cacheability = $cacheability->merge($links['cacheability']);
// Do not display single tabs.
$tabs += ['#secondary' => count(Element::getVisibleChildren($links['tabs'])) > 1 ? $links['tabs'] : []];
}
$build = [];
$cacheability->applyTo($build);
if (empty($tabs['#primary']) && empty($tabs['#secondary'])) {
return $build;
}
return $build + $tabs;
}
示例11: postRender
/**
* Inserts the rendered elements into the format string.
*
* @param string $content
* The rendered element.
* @param array $element
* An associative array containing the properties and children of the
* element.
*
* @return string
* The new rendered element.
*/
public static function postRender($content, array $element)
{
/** @var \Drupal\address\Entity\AddressFormatInterface $address_format */
$address_format = $element['address_format']['#value'];
$format_string = $address_format->getFormat();
// Add the country to the bottom or the top of the format string,
// depending on whether the format is minor-to-major or major-to-minor.
if (strpos($format_string, AddressField::ADDRESS_LINE1) < strpos($format_string, AddressField::ADDRESS_LINE2)) {
$format_string .= "\n" . '%country';
} else {
$format_string = '%country' . "\n" . $format_string;
}
$replacements = [];
foreach (Element::getVisibleChildren($element) as $key) {
$child = $element[$key];
if (isset($child['#placeholder'])) {
$replacements[$child['#placeholder']] = $child['#value'] ? $child['#markup'] : '';
}
}
$content = self::replacePlaceholders($format_string, $replacements);
$content = nl2br($content, FALSE);
return $content;
}
示例12: viewElements
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode)
{
$element = array();
$settings = $this->getSettings();
$items_array = array();
foreach ($items as $item) {
$items_array[] = $item;
}
// Merge defaults from the formatters and ensure proper ordering.
$this->prepareFormatters($this->fieldDefinition->getType(), $settings['formatters']);
// Loop through each formatter in order.
foreach ($settings['formatters'] as $name => $options) {
// Run any unrendered items through the formatter.
$formatter_items = array_diff_key($items_array, $element);
$formatter_instance = $this->getFormatter($options);
$formatter_instance->prepareView(array($items->getEntity()->id() => $items));
if ($result = $formatter_instance->viewElements($items, $langcode)) {
// Only add visible content from the formatter's render array result
// that matches an unseen delta.
$visible_deltas = Element::getVisibleChildren($result);
$visible_deltas = array_intersect($visible_deltas, array_keys($formatter_items));
$element += array_intersect_key($result, array_flip($visible_deltas));
// If running this formatter completed the output for all items, then
// there is no need to loop through the rest of the formatters.
if (count($element) == count($items_array)) {
break;
}
}
}
// Ensure the resulting elements are ordered properly by delta.
ksort($element);
return $element;
}
示例13: getVisibleChildren
/**
* Returns the visible children of an element.
*
* @return array
* The array keys of the element's visible children.
*/
public function getVisibleChildren()
{
return \Drupal\Core\Render\Element::getVisibleChildren($this->array);
}
示例14: preRenderVerticalTabs
/**
* Prepares a vertical_tabs element for rendering.
*
* @param array $element
* An associative array containing the properties and children of the
* vertical tabs element.
*
* @return array
* The modified element.
*/
public static function preRenderVerticalTabs($element)
{
// Do not render the vertical tabs element if it is empty.
$group = implode('][', $element['#parents']);
if (!Element::getVisibleChildren($element['group']['#groups'][$group])) {
$element['#printed'] = TRUE;
}
return $element;
}
示例15: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$form = parent::buildForm($form, $form_state);
$flood_config = $this->config('user.flood');
$contact_config = $this->config('contact.settings');
$form['user'] = array('#type' => 'fieldset', '#title' => t('Login Flooding'), '#access' => \Drupal::currentUser()->hasPermission('administer users'));
$form['user']['ip_limit'] = array('#type' => 'select', '#title' => t('Failed login (IP) limit'), '#options' => array_combine(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 75, 100, 125, 150, 200, 250, 500), array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 75, 100, 125, 150, 200, 250, 500)), '#default_value' => $flood_config->get('ip_limit', 50));
$form['user']['ip_window'] = array('#type' => 'select', '#title' => $this->t('Failed login (IP) window'), '#options' => array_combine(array(60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), array(60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400)), '#default_value' => $flood_config->get('ip_window', 3600));
$form['user']['user_limit'] = array('#type' => 'select', '#title' => t('Failed login (username) limit'), '#options' => array_combine(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 75, 100, 125, 150, 200, 250, 500), array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 75, 100, 125, 150, 200, 250, 500)), '#default_value' => $flood_config->get('user_limit', 5));
$form['user']['user_window'] = array('#type' => 'select', '#title' => t('Failed login (username) window'), '#options' => array_combine(array(60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), array(60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400)), '#default_value' => $flood_config->get('user_window', 21600));
// Contact module flood events.
$form['contact'] = array('#type' => 'fieldset', '#title' => t('Contact Forms Flooding'), '#access' => \Drupal::currentUser()->hasPermission('administer contact forms'));
$form['contact']['flood']['limit'] = array('#type' => 'select', '#title' => t('Emails sent limit'), '#options' => array_combine(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 75, 100, 125, 150, 200, 250, 500), array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 75, 100, 125, 150, 200, 250, 500)), '#default_value' => $contact_config->get('flood.limit', 5));
$form['contact']['flood']['interval'] = array('#type' => 'select', '#title' => t('Emails sent window'), '#options' => array_combine(array(60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), array(60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400)), '#default_value' => $contact_config->get('flood.interval', 3600));
// Show a message if the user does not have any access to any options.
if (!Element::getVisibleChildren($form)) {
$form['nothing'] = array('#markup' => '<p>' . t('Sorry, there are no flood control options for you to configure.') . '</p>');
return $form;
} else {
return $form;
}
}