Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #2837777 by jsacksick: Provide a commerce_plugin_radios field w…
…idget
- Loading branch information
Showing
7 changed files
with
216 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Drupal\commerce\Event; | ||
|
||
/** | ||
* Defines events for the base Commerce module. | ||
* | ||
* Note that submodules have their own defined events. | ||
*/ | ||
final class CommerceEvents { | ||
|
||
/** | ||
* Name of the event fired when altering the referenceable plugin types. | ||
* | ||
* @Event | ||
* | ||
* @see \Drupal\commerce\Event\ReferenceablePluginTypesEvent.php | ||
*/ | ||
const REFERENCEABLE_PLUGIN_TYPES = 'commerce.referenceable_plugin_types'; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Drupal\commerce\Event; | ||
|
||
use Symfony\Component\EventDispatcher\Event; | ||
|
||
/** | ||
* Defines the referenceable plugin types event. | ||
* | ||
* @see \Drupal\commerce\Event\CommerceEvents | ||
*/ | ||
class ReferenceablePluginTypesEvent extends Event { | ||
|
||
/** | ||
* The plugin types, in the id => label format. | ||
* | ||
* @var array | ||
*/ | ||
protected $pluginTypes; | ||
|
||
/** | ||
* Constructs a new ReferenceablePluginTypesEvent object. | ||
* | ||
* @param array $plugin_types | ||
* The plugin types, in the id => label format. | ||
*/ | ||
public function __construct(array $plugin_types) { | ||
$this->pluginTypes = $plugin_types; | ||
} | ||
|
||
/** | ||
* Gets the plugin types. | ||
* | ||
* @return array | ||
* The plugin types, in the id => label format. | ||
*/ | ||
public function getPluginTypes() { | ||
return $this->pluginTypes; | ||
} | ||
|
||
/** | ||
* Sets the plugin types. | ||
* | ||
* @param array $plugin_types | ||
* The plugin types, in the id => label format. | ||
* | ||
* @return $this | ||
*/ | ||
public function setPluginTypes(array $plugin_types) { | ||
$this->pluginTypes = $plugin_types; | ||
return $this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Drupal\commerce\Plugin\Field\FieldWidget; | ||
|
||
use Drupal\Core\Field\FieldItemListInterface; | ||
use Drupal\Core\Form\FormStateInterface; | ||
|
||
/** | ||
* Plugin implementation of the 'commerce_plugin_radios' widget. | ||
* | ||
* @FieldWidget( | ||
* id = "commerce_plugin_radios", | ||
* label = @Translation("Plugin radios"), | ||
* field_types = { | ||
* "commerce_plugin_item" | ||
* }, | ||
* ) | ||
*/ | ||
class PluginRadiosWidget extends PluginSelectWidget { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { | ||
list($field_type, $plugin_type) = explode(':', $this->fieldDefinition->getType()); | ||
return [ | ||
'#type' => 'commerce_plugin_select', | ||
'#plugin_element_type' => 'radios', | ||
'#plugin_type' => $plugin_type, | ||
'#categories' => $this->fieldDefinition->getSetting('categories'), | ||
'#default_value' => [ | ||
'target_plugin_id' => $items[$delta]->target_plugin_id, | ||
'target_plugin_configuration' => $items[$delta]->target_plugin_configuration, | ||
], | ||
'#required' => $this->fieldDefinition->isRequired(), | ||
'#title' => $this->fieldDefinition->getLabel(), | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters