Skip to main content
added 181 characters in body
Source Link
Tyler Durden
  • 2.3k
  • 2
  • 27
  • 44

I am trying to create a twig template for user edit page.

I have tried

/**
 * Implements hook_theme_suggestions_alter().
 */
function my_module_user_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
  if($variables['element']['#type'] == 'form' && $variables['element']['#form_id'] == 'user_form') {
    $original_theme_hook = $variables['theme_hook_original'];
    $suggestions[] = $original_theme_hook . '__bs_' . str_replace('-', '_', $variables['element']['#id']);
  }
  return $suggestions;
}

I have added my template in my module under templates/form__bs_user_form.html.twig

I have also added in my form_alter:

$form['#theme'] = ['bs_user_form'];

and

function my_module_user_theme($existing, $type, $theme, $path) {
  return [
    'bs_user_form' => [
      'render element' => 'form',
      ],
  ];
}

It does retrieve this error: Argument 1 passed to Drupal\Core\Render\Element::setAttributes() must be of the type array, null given

How can I assign a template to the user edit form?


Solved, I removed my_module_user_theme_suggestions_alter and I got it working. If anyone has a better solution feel free to add it to the answers.

I am trying to create a twig template for user edit page.

I have tried

/**
 * Implements hook_theme_suggestions_alter().
 */
function my_module_user_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
  if($variables['element']['#type'] == 'form' && $variables['element']['#form_id'] == 'user_form') {
    $original_theme_hook = $variables['theme_hook_original'];
    $suggestions[] = $original_theme_hook . '__bs_' . str_replace('-', '_', $variables['element']['#id']);
  }
  return $suggestions;
}

I have added my template in my module under templates/form__bs_user_form.html.twig

I have also added in my form_alter:

$form['#theme'] = ['bs_user_form'];

and

function my_module_user_theme($existing, $type, $theme, $path) {
  return [
    'bs_user_form' => [
      'render element' => 'form',
      ],
  ];
}

It does retrieve this error: Argument 1 passed to Drupal\Core\Render\Element::setAttributes() must be of the type array, null given

How can I assign a template to the user edit form?

I am trying to create a twig template for user edit page.

I have tried

/**
 * Implements hook_theme_suggestions_alter().
 */
function my_module_user_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
  if($variables['element']['#type'] == 'form' && $variables['element']['#form_id'] == 'user_form') {
    $original_theme_hook = $variables['theme_hook_original'];
    $suggestions[] = $original_theme_hook . '__bs_' . str_replace('-', '_', $variables['element']['#id']);
  }
  return $suggestions;
}

I have added my template in my module under templates/form__bs_user_form.html.twig

I have also added in my form_alter:

$form['#theme'] = ['bs_user_form'];

and

function my_module_user_theme($existing, $type, $theme, $path) {
  return [
    'bs_user_form' => [
      'render element' => 'form',
      ],
  ];
}

It does retrieve this error: Argument 1 passed to Drupal\Core\Render\Element::setAttributes() must be of the type array, null given

How can I assign a template to the user edit form?


Solved, I removed my_module_user_theme_suggestions_alter and I got it working. If anyone has a better solution feel free to add it to the answers.

removed tags from the title
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

D8 - How todo I assign a template forto the user edit form?

Source Link
Tyler Durden
  • 2.3k
  • 2
  • 27
  • 44

D8 - How to assign a template for user edit form

I am trying to create a twig template for user edit page.

I have tried

/**
 * Implements hook_theme_suggestions_alter().
 */
function my_module_user_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
  if($variables['element']['#type'] == 'form' && $variables['element']['#form_id'] == 'user_form') {
    $original_theme_hook = $variables['theme_hook_original'];
    $suggestions[] = $original_theme_hook . '__bs_' . str_replace('-', '_', $variables['element']['#id']);
  }
  return $suggestions;
}

I have added my template in my module under templates/form__bs_user_form.html.twig

I have also added in my form_alter:

$form['#theme'] = ['bs_user_form'];

and

function my_module_user_theme($existing, $type, $theme, $path) {
  return [
    'bs_user_form' => [
      'render element' => 'form',
      ],
  ];
}

It does retrieve this error: Argument 1 passed to Drupal\Core\Render\Element::setAttributes() must be of the type array, null given

How can I assign a template to the user edit form?