当前位置: 首页>>代码示例>>PHP>>正文


PHP Element::setAttributes方法代码示例

本文整理汇总了PHP中Drupal\Core\Render\Element::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Element::setAttributes方法的具体用法?PHP Element::setAttributes怎么用?PHP Element::setAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Render\Element的用法示例。


在下文中一共展示了Element::setAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: preRenderRange

 /**
  * Prepares a #type 'range' render element for input.html.twig.
  *
  * @param array $element
  *   An associative array containing the properties of the element.
  *   Properties used: #title, #value, #description, #min, #max, #attributes,
  *   #step.
  *
  * @return array
  *   The $element with prepared variables ready for input.html.twig.
  */
 public static function preRenderRange($element)
 {
     $element['#attributes']['type'] = 'range';
     Element::setAttributes($element, array('id', 'name', 'value', 'step', 'min', 'max'));
     static::setAttributes($element, array('form-range'));
     return $element;
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:18,代码来源:Range.php

示例2: bootstrap_preprocess_input

/**
 * Preprocess input.
 */
function bootstrap_preprocess_input(&$variables)
{
    $element =& $variables['element'];
    $attributes = new Attribute($variables['attributes']);
    // Set the element's attributes.
    \Drupal\Core\Render\Element::setAttributes($element, array('id', 'name', 'value', 'type'));
    // Handle button inputs.
    if (_bootstrap_is_button($element)) {
        $variables['attributes']['class'][] = 'btn';
        _bootstrap_colorize_button($variables);
        _bootstrap_iconize_button($element);
        // Add button size, if necessary.
        if ($size = bootstrap_setting('button_size')) {
            $variables['attributes']['class'][] = $size;
        }
        // Add in the button type class.
        $variables['attributes']['class'][] = 'form-' . $element['#type'];
        $variables['label'] = $element['#value'];
    }
    _bootstrap_prerender_input($variables);
    // Autocomplete fields.
    if (!empty($element['#autocomplete_route_name']) && Drupal::PathValidator($element['#autocomplete_route_name'])) {
        $variables['autocomplete'] = TRUE;
        // Attributes for hidden input field.
        $autocomplete_attributes = new Attribute();
        $autocomplete_attributes['type'] = 'hidden';
        $autocomplete_attributes['id'] = $element['#attributes']['id'] . '-autocomplete';
        $autocomplete_attributes['value'] = Drupal::Url($element['#autocomplete_route_name'], $element['#autocomplete_route_parameters']);
        $autocomplete_attributes['disabled'] = 'disabled';
        $autocomplete_attributes['class'] = 'autocomplete';
        // Uses icon for autocomplete "throbber".
        $icon = _bootstrap_icon('refresh');
        // Fallback to using core's throbber.
        if (empty($icon)) {
            $icon = array('#type' => 'container', '#attributes' => array('class' => array('ajax-progress', 'ajax-progress-throbber', 'invisible')), 'throbber' => array('#type' => 'html_tag', '#tag' => 'div', '#attributes' => array('class' => array('throbber'))));
        }
        $variables['autocomplete_icon'] = $icon;
        $variables['autocomplete_attributes'] = $autocomplete_attributes;
    }
    // Search fields.
    if ($element['#type'] == 'search') {
        $attributes['placeholder'] = t('Search');
        $attributes['data-original-title'] = t('Enter the terms you wish to search for.');
    }
    // Additional Twig variables.
    $variables['icon'] = $element['#icon'];
    $variables['element'] = $element;
}
开发者ID:sathishRio,项目名称:themes,代码行数:51,代码来源:input.vars.php

示例3: map

 /**
  * Maps an element's properties to its attributes array.
  *
  * @param array $map
  *   An associative array whose keys are element property names and whose
  *   values are the HTML attribute names to set on the corresponding
  *   property; e.g., array('#propertyname' => 'attributename'). If both names
  *   are identical except for the leading '#', then an attribute name value is
  *   sufficient and no property name needs to be specified.
  *
  * @return $this
  */
 public function map(array $map)
 {
     \Drupal\Core\Render\Element::setAttributes($this->array, $map);
     return $this;
 }
开发者ID:Suite5,项目名称:feelmybook,代码行数:17,代码来源:Element.php

示例4: preRenderNumber

 /**
  * Prepares a #type 'number' render element for theme_input().
  *
  * @param array $element
  *   An associative array containing the properties of the element.
  *   Properties used: #title, #value, #description, #min, #max, #placeholder,
  *   #required, #attributes, #step, #size.
  *
  * @return array
  *   The $element with prepared variables ready for theme_input().
  */
 public static function preRenderNumber($element)
 {
     $element['#attributes']['type'] = 'number';
     Element::setAttributes($element, array('id', 'name', 'value', 'step', 'min', 'max', 'placeholder', 'size'));
     static::setAttributes($element, array('form-number'));
     return $element;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:18,代码来源:Number.php

示例5: preRenderUrl

 /**
  * Prepares a #type 'url' render element for input.html.twig.
  *
  * @param array $element
  *   An associative array containing the properties of the element.
  *   Properties used: #title, #value, #description, #size, #maxlength,
  *   #placeholder, #required, #attributes.
  *
  * @return array
  *   The $element with prepared variables ready for input.html.twig.
  */
 public static function preRenderUrl($element)
 {
     $element['#attributes']['type'] = 'url';
     Element::setAttributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder'));
     static::setAttributes($element, array('form-url'));
     return $element;
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:18,代码来源:Url.php

示例6: preRenderRadio

 /**
  * Prepares a #type 'radio' render element for theme_input().
  *
  * @param array $element
  *   An associative array containing the properties of the element.
  *   Properties used: #required, #return_value, #value, #attributes, #title,
  *   #description.
  *
  * Note: The input "name" attribute needs to be sanitized before output, which
  *       is currently done by initializing Drupal\Core\Template\Attribute with
  *       all the attributes.
  *
  * @return array
  *   The $element with prepared variables ready for theme_input().
  */
 public static function preRenderRadio($element)
 {
     $element['#attributes']['type'] = 'radio';
     Element::setAttributes($element, array('id', 'name', '#return_value' => 'value'));
     if (isset($element['#return_value']) && $element['#value'] !== FALSE && $element['#value'] == $element['#return_value']) {
         $element['#attributes']['checked'] = 'checked';
     }
     static::setAttributes($element, array('form-radio'));
     return $element;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:25,代码来源:Radio.php

示例7: preRenderButton

 /**
  * Prepares a #type 'button' render element for theme_input().
  *
  * @param array $element
  *   An associative array containing the properties of the element.
  *   Properties used: #attributes, #button_type, #name, #value.
  *
  * The #button_type property accepts any value, though core themes have CSS that
  * styles the following button_types appropriately: 'primary', 'danger'.
  *
  * @return array
  *   The $element with prepared variables ready for theme_input().
  */
 public static function preRenderButton($element)
 {
     $element['#attributes']['type'] = 'submit';
     Element::setAttributes($element, array('id', 'name', 'value'));
     $element['#attributes']['class'][] = 'button';
     if (!empty($element['#button_type'])) {
         $element['#attributes']['class'][] = 'button--' . $element['#button_type'];
     }
     // @todo Various JavaScript depends on this button class.
     $element['#attributes']['class'][] = 'form-submit';
     if (!empty($element['#attributes']['disabled'])) {
         $element['#attributes']['class'][] = 'is-disabled';
     }
     return $element;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:28,代码来源:Button.php

示例8: preRenderButton

 /**
  * Prepares a #type 'button' render element for input.html.twig.
  *
  * @param array $element
  *   An associative array containing the properties of the element.
  *   Properties used: #attributes, #button_type, #name, #value.
  *
  * The #button_type property accepts any value, though core themes have CSS that
  * styles the following button_types appropriately: 'primary', 'danger'.
  *
  * @return array
  *   The $element with prepared variables ready for input.html.twig.
  */
 public static function preRenderButton($element)
 {
     $element['#attributes']['type'] = 'submit';
     Element::setAttributes($element, array('id', 'name', 'value'));
     $element['#attributes']['class'][] = 'button';
     if (!empty($element['#button_type'])) {
         $element['#attributes']['class'][] = 'button--' . $element['#button_type'];
     }
     $element['#attributes']['class'][] = 'js-form-submit';
     $element['#attributes']['class'][] = 'form-submit';
     if (!empty($element['#attributes']['disabled'])) {
         $element['#attributes']['class'][] = 'is-disabled';
     }
     return $element;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:28,代码来源:Button.php

示例9: preRenderLinkitElement

  /**
   * Prepares a #type 'linkit' render element for input.html.twig.
   *
   * @param array $element
   *   An associative array containing the properties of the element.
   *   Properties used: #title, #value, #description, #size, #attributes.
   *
   * @return array
   *   The $element with prepared variables ready for input.html.twig.
   */
  public static function preRenderLinkitElement($element) {
    $element['#attributes']['type'] = 'text';
    Element::setAttributes($element, array('id', 'name', 'value', 'size'));
    static::setAttributes($element, array('form-text'));

    return $element;
  }
开发者ID:eloiv,项目名称:botafoc.cat,代码行数:17,代码来源:Linkit.php

示例10: preRenderTable

 /**
  * #pre_render callback to transform children of an element into #rows suitable for theme_table().
  *
  * This function converts sub-elements of an element of #type 'table' to be
  * suitable for theme_table():
  * - The first level of sub-elements are table rows. Only the #attributes
  *   property is taken into account.
  * - The second level of sub-elements is converted into columns for the
  *   corresponding first-level table row.
  *
  * Simple example usage:
  * @code
  * $form['table'] = array(
  *   '#type' => 'table',
  *   '#header' => array(t('Title'), array('data' => t('Operations'), 'colspan' => '1')),
  *   // Optionally, to add tableDrag support:
  *   '#tabledrag' => array(
  *     array(
  *       'action' => 'order',
  *       'relationship' => 'sibling',
  *       'group' => 'thing-weight',
  *     ),
  *   ),
  * );
  * foreach ($things as $row => $thing) {
  *   $form['table'][$row]['#weight'] = $thing['weight'];
  *
  *   $form['table'][$row]['title'] = array(
  *     '#type' => 'textfield',
  *     '#default_value' => $thing['title'],
  *   );
  *
  *   // Optionally, to add tableDrag support:
  *   $form['table'][$row]['#attributes']['class'][] = 'draggable';
  *   $form['table'][$row]['weight'] = array(
  *     '#type' => 'textfield',
  *     '#title' => t('Weight for @title', array('@title' => $thing['title'])),
  *     '#title_display' => 'invisible',
  *     '#size' => 4,
  *     '#default_value' => $thing['weight'],
  *     '#attributes' => array('class' => array('thing-weight')),
  *   );
  *
  *   // The amount of link columns should be identical to the 'colspan'
  *   // attribute in #header above.
  *   $form['table'][$row]['edit'] = array(
  *     '#type' => 'link',
  *     '#title' => t('Edit'),
  *     '#url' => Url::fromRoute('entity.test_entity.edit_form', ['test_entity' => $row]),
  *   );
  * }
  * @endcode
  *
  * @param array $element
  *   A structured array containing two sub-levels of elements. Properties used:
  *   - #tabledrag: The value is a list of $options arrays that are passed to
  *     drupal_attach_tabledrag(). The HTML ID of the table is added to each
  *     $options array.
  *
  * @return array
  *
  * @see theme_table()
  * @see drupal_process_attached()
  * @see drupal_attach_tabledrag()
  */
 public static function preRenderTable($element)
 {
     foreach (Element::children($element) as $first) {
         $row = array('data' => array());
         // Apply attributes of first-level elements as table row attributes.
         if (isset($element[$first]['#attributes'])) {
             $row += $element[$first]['#attributes'];
         }
         // Turn second-level elements into table row columns.
         // @todo Do not render a cell for children of #type 'value'.
         // @see http://drupal.org/node/1248940
         foreach (Element::children($element[$first]) as $second) {
             // Assign the element by reference, so any potential changes to the
             // original element are taken over.
             $column = array('data' => &$element[$first][$second]);
             // Apply wrapper attributes of second-level elements as table cell
             // attributes.
             if (isset($element[$first][$second]['#wrapper_attributes'])) {
                 $column += $element[$first][$second]['#wrapper_attributes'];
             }
             $row['data'][] = $column;
         }
         $element['#rows'][] = $row;
     }
     // Take over $element['#id'] as HTML ID attribute, if not already set.
     Element::setAttributes($element, array('id'));
     // Add sticky headers, if applicable.
     if (count($element['#header']) && $element['#sticky']) {
         $element['#attached']['library'][] = 'core/drupal.tableheader';
         // Add 'sticky-enabled' class to the table to identify it for JS.
         // This is needed to target tables constructed by this function.
         $element['#attributes']['class'][] = 'sticky-enabled';
     }
     // If the table has headers and it should react responsively to columns hidden
     // with the classes represented by the constants RESPONSIVE_PRIORITY_MEDIUM
//.........这里部分代码省略.........
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:101,代码来源:Table.php

示例11: preRenderSelect

 /**
  * Prepares a select render element.
  */
 public static function preRenderSelect($element)
 {
     Element::setAttributes($element, array('id', 'name', 'size'));
     static::setAttributes($element, array('form-select'));
     return $element;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:9,代码来源:Select.php

示例12: preRenderPassword

 /**
  * Prepares a #type 'password' render element for input.html.twig.
  *
  * @param array $element
  *   An associative array containing the properties of the element.
  *   Properties used: #title, #value, #description, #size, #maxlength,
  *   #placeholder, #required, #attributes.
  *
  * @return array
  *   The $element with prepared variables ready for input.html.twig.
  */
 public static function preRenderPassword($element)
 {
     $element['#attributes']['type'] = 'password';
     Element::setAttributes($element, array('id', 'name', 'size', 'maxlength', 'placeholder'));
     static::setAttributes($element, array('form-text'));
     return $element;
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:18,代码来源:Password.php

示例13: preRenderQuantity

 /**
  * Prepares a #type 'uc_quantity' render element for theme_input().
  *
  * @param array $element
  *   An associative array containing the properties of the element.
  *   Properties used: #title, #value, #description, #size, #maxlength,
  *   #placeholder, #min, #max, #step, #required, #attributes.
  *
  * @return array
  *   The $element with prepared variables ready for theme_input().
  */
 public static function preRenderQuantity($element)
 {
     $element['#attributes']['type'] = 'number';
     $element['#attributes']['min'] = 0;
     $element['#attributes']['step'] = 1;
     Element::setAttributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder', 'min', 'max', 'step'));
     static::setAttributes($element, array('form-uc-quantity'));
     return $element;
 }
开发者ID:pedrocones,项目名称:hydrotools,代码行数:20,代码来源:UcQuantity.php

示例14: preRenderDate

 /**
  * Adds form-specific attributes to a 'date' #type element.
  *
  * Supports HTML5 types of 'date', 'datetime', 'datetime-local', and 'time'.
  * Falls back to a plain textfield with JS datepicker support. Used as a
  * sub-element by the datetime element type.
  *
  * @param array $element
  *   An associative array containing the properties of the element.
  *   Properties used: #title, #value, #options, #description, #required,
  *   #attributes, #id, #name, #type, #min, #max, #step, #value, #size. The
  *   #name property will be sanitized before output. This is currently done by
  *   initializing Drupal\Core\Template\Attribute with all the attributes.
  *
  * @return array
  *   The $element with prepared variables ready for #theme 'input__date'.
  */
 public static function preRenderDate($element)
 {
     if (empty($element['#attributes']['type'])) {
         $element['#attributes']['type'] = 'date';
     }
     Element::setAttributes($element, array('id', 'name', 'type', 'min', 'max', 'step', 'value', 'size'));
     static::setAttributes($element, array('form-' . $element['#attributes']['type']));
     return $element;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:26,代码来源:Date.php

示例15: preRenderCheckbox

 /**
  * Prepares a #type 'checkbox' render element for input.html.twig.
  *
  * @param array $element
  *   An associative array containing the properties of the element.
  *   Properties used: #title, #value, #return_value, #description, #required,
  *   #attributes, #checked.
  *
  * @return array
  *   The $element with prepared variables ready for input.html.twig.
  */
 public static function preRenderCheckbox($element)
 {
     $element['#attributes']['type'] = 'checkbox';
     Element::setAttributes($element, array('id', 'name', '#return_value' => 'value'));
     // Unchecked checkbox has #value of integer 0.
     if (!empty($element['#checked'])) {
         $element['#attributes']['checked'] = 'checked';
     }
     static::setAttributes($element, array('form-checkbox'));
     return $element;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:22,代码来源:Checkbox.php


注:本文中的Drupal\Core\Render\Element::setAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。