WorkflowDefaultWidget.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * @file
  4. * Contains workflow\includes\Field\WorkflowDefaultWidget.
  5. */
  6. /**
  7. * Plugin implementation of the 'workflow_default' widget.
  8. */
  9. class WorkflowDefaultWidget extends WorkflowD7Base { // D8: extends WidgetBase {
  10. /**
  11. * Returns the settings.
  12. *
  13. * @todo d8: Replace by the 'annotations' in D8 (See comments above this class).
  14. */
  15. public static function settings() {
  16. return array(
  17. 'workflow_default' => array(
  18. 'label' => t('Workflow'),
  19. 'field types' => array('workflow'),
  20. 'settings' => array(
  21. 'name_as_title' => 1,
  22. 'fieldset' => 0,
  23. 'comment' => 1,
  24. ),
  25. ),
  26. );
  27. }
  28. /**
  29. * Implements hook_field_widget_settings_form() --> WidgetInterface::settingsForm().
  30. *
  31. * {@inheritdoc}
  32. *
  33. * The Widget Instance has no settings. To have a uniform UX, all settings are done on the Field level.
  34. */
  35. public function settingsForm(array $form, array &$form_state, $has_data) {
  36. $element = array();
  37. return $element;
  38. }
  39. /**
  40. * Implements hook_field_widget_form --> WidgetInterface::formElement().
  41. *
  42. * {@inheritdoc}
  43. *
  44. * Be careful: Widget may be shown in very different places. Test carefully!!
  45. * - On a entity add/edit page
  46. * - On a entity preview page
  47. * - On a entity view page
  48. * - On a entity 'workflow history' tab
  49. * - On a comment display, in the comment history
  50. * - On a comment form, below the comment history
  51. *
  52. * @todo D8: change "array $items" to "FieldInterface $items"
  53. */
  54. public function formElement(array $items, $delta, array $element, array &$form, array &$form_state) {
  55. $field = $this->field;
  56. $instance = $this->instance;
  57. $entity = $this->entity;
  58. $entity_type = $this->entity_type;
  59. // Add the element. Do not use drupal_get_form, or you will have a form in a form.
  60. workflow_transition_form($form, $form_state, $field, $instance, $entity_type, $entity);
  61. }
  62. /**
  63. * Implements workflow_transition() -> WorkflowDefaultWidget::submit().
  64. *
  65. * Overrides submit(array $form, array &$form_state).
  66. * Contains 2 extra parameters for D7
  67. *
  68. * @param array $form
  69. * @param array $form_state
  70. * @param array $items
  71. * The value of the field.
  72. * @param bool $force
  73. * TRUE if all access must be overridden, e.g., for Rules.
  74. *
  75. * @return int
  76. * If update succeeded, the new State Id. Else, the old Id is returned.
  77. *
  78. * This is called from function _workflowfield_form_submit($form, &$form_state)
  79. * It is a replacement of function workflow_transition($node, $new_sid, $force, $field)
  80. * It performs the following actions;
  81. * - save a scheduled action
  82. * - update history
  83. * - restore the normal $items for the field.
  84. * @todo: remove update of {node_form} table. (separate task, because it has features, too)
  85. */
  86. public function submit(array $form, array &$form_state, array &$items, $force = FALSE) {
  87. return workflow_transition_form_submit($form, $form_state);
  88. }
  89. /**
  90. * Implements hook_field_widget_error --> WidgetInterface::errorElement().
  91. */
  92. // public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, array &$form_state) {
  93. // }
  94. // public function settingsSummary() {
  95. // }
  96. // public function massageFormValues(array $values, array $form, array &$form_state) {
  97. // }
  98. }