Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ImageButton.php

function ImageButton::preRenderButton

Overrides Button::preRenderButton

File

core/lib/Drupal/Core/Render/Element/ImageButton.php, line 69

Class

ImageButton
Provides a form element for a submit button with an image.

Namespace

Drupal\Core\Render\Element

Code

public static function preRenderButton($element) {
    $element['#attributes']['type'] = 'image';
    Element::setAttributes($element, [
        'id',
        'name',
        'value',
    ]);
    $element['#attributes']['src'] = \Drupal::service('file_url_generator')->generateString($element['#src']);
    if (!empty($element['#title'])) {
        $element['#attributes']['alt'] = $element['#title'];
        $element['#attributes']['title'] = $element['#title'];
    }
    $element['#attributes']['class'][] = 'image-button';
    if (!empty($element['#button_type'])) {
        $element['#attributes']['class'][] = 'image-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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal