Skip to content

Instantly share code, notes, and snippets.

@shadcn
Last active August 8, 2017 09:01
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shadcn/1f434a2c720f16fe99d663d033b04f3c to your computer and use it in GitHub Desktop.
Save shadcn/1f434a2c720f16fe99d663d033b04f3c to your computer and use it in GitHub Desktop.
Add an actions_no_dropbutton Element to render form actions without the dropbutton
<?php
namespace Drupal\et_article\Element;
use Drupal\Core\Render\Element\Actions;
/**
* Provides a wrapper element to render buttons for a form.
*
* Usage example:
* @code
* $form['actions'] = array('#type' => 'actions_no_dropbutton');
* $form['actions']['submit'] = array(
* '#type' => 'submit',
* '#value' => $this->t('Save'),
* );
* @endcode
*
* @RenderElement("actions_no_dropbutton")
*/
class ActionsNoDropButton extends Actions {
/**
* {@inheritdoc}
*/
public function getInfo() {
$info = parent::getInfo();
// Unset the Actions::preRenderActionsDropbutton process callback.
foreach ($info['#process'] as $key => $process) {
if ($process[1] == 'preRenderActionsDropbutton') {
unset($info['#process'][$key]);
break;
}
}
return $info;
}
}
@shadcn
Copy link
Author

shadcn commented Dec 7, 2016

Usage

<?php

// Change the type of the actions.
$form['actions']['#type'] = 'actions_no_dropbutton';

Screenshot

actions_no_dropbutton

@rachellawson
Copy link

Ah!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment