-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
slight refactor and scaffold form node plugin
- Loading branch information
Showing
7 changed files
with
148 additions
and
12 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
42 changes: 42 additions & 0 deletions
42
web/modules/custom/sfgov_api/src/Plugin/SfgApi/Node/FormConfirmationPage.php
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,42 @@ | ||
<?php | ||
|
||
namespace Drupal\sfgov_api\Plugin\SfgApi\Node; | ||
|
||
use Drupal\sfgov_api\Plugin\SfgApi\ApiFieldHelperTrait; | ||
|
||
/** | ||
* Plugin implementation of the sfgov_api. | ||
* | ||
* @SfgApi( | ||
* id = "node_form_confirmation_page", | ||
* title = @Translation("Node form_confirmation_page"), | ||
* bundle = "form_confirmation_page", | ||
* wag_bundle = "form_confirmation_page", | ||
* entity_id = {}, | ||
* langcode = {}, | ||
* ) | ||
*/ | ||
class FormConfirmationPage extends SfgApiNodeBase { | ||
|
||
use ApiFieldHelperTrait; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setCustomData($entity) { | ||
return [ | ||
// @todo this plugin is incomplete | ||
'body' => $entity->get('body')->value, | ||
'field_bann' => $entity->get('field_bann')->value, | ||
'field_banner_color' => $entity->get('field_banner_color')->value, | ||
'field_banner_image' => $entity->get('field_banner_image')->value, | ||
'field_confirmation_sidebar' => $entity->get('field_confirmation_sidebar')->value, | ||
'field_departments' => $entity->get('field_departments')->value, | ||
'field_description' => $entity->get('field_description')->value, | ||
// 'field_form_confirm_page_slug' => $entity->get('field_form_confirm_page_slug')->value, | ||
// 'field_related_content_single' => $entity->get('field_related_content_single')->value, | ||
// 'field_step' => $entity->get('field_step')->value, | ||
]; | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
web/modules/custom/sfgov_api/src/Plugin/SfgApi/Node/FormPage.php
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,60 @@ | ||
<?php | ||
|
||
namespace Drupal\sfgov_api\Plugin\SfgApi\Node; | ||
|
||
use Drupal\node\Entity\Node; | ||
use Drupal\sfgov_api\Plugin\SfgApi\ApiFieldHelperTrait; | ||
|
||
/** | ||
* Plugin implementation of the sfgov_api. | ||
* | ||
* @SfgApi( | ||
* id = "node_form_page", | ||
* title = @Translation("Node form_page"), | ||
* bundle = "form_page", | ||
* wag_bundle = "form_page", | ||
* entity_id = {}, | ||
* langcode = {}, | ||
* ) | ||
*/ | ||
class FormPage extends SfgApiNodeBase { | ||
|
||
use ApiFieldHelperTrait; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setCustomData($entity) { | ||
$formio_data_source = $this->getReferencedData($entity->get('field_form_id')->referencedEntities()); | ||
return [ | ||
// @todo this plugin is incomplete | ||
// 'field_formio_json_content' => $entity->get('field_formio_json_content')->value, | ||
// 'field_form_id' => $entity->get('field_form_id')->value, | ||
// 'field_intro_text' => $entity->get('field_intro_text')->value, | ||
'data_source' => $formio_data_source[0]['value']['formio_data_source'], | ||
'confirmation_page' => $this->getReferencedData([$this->getFormConfirmationPage($entity->id())]), | ||
]; | ||
} | ||
|
||
/** | ||
* Get the form confirmation page for a given form. WIP. | ||
* | ||
* @param int $form_id | ||
* The form id. | ||
* | ||
* @return array | ||
* The form confirmation page. | ||
*/ | ||
public function getFormConfirmationPage($form_id) { | ||
$query = \Drupal::entityQuery('node') | ||
->condition('type', 'form_confirmation_page') | ||
->condition('field_related_content_single', $form_id); | ||
$nids = $query->execute(); | ||
if (count($nids) > 0) { | ||
$nid = array_shift($nids); | ||
return Node::load($nid); | ||
} | ||
return []; | ||
} | ||
|
||
} |
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
36 changes: 36 additions & 0 deletions
36
web/modules/custom/sfgov_api/src/Plugin/SfgApi/Paragraph/FormIo.php
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,36 @@ | ||
<?php | ||
|
||
namespace Drupal\sfgov_api\Plugin\SfgApi\Paragraph; | ||
|
||
/** | ||
* Plugin implementation of the sfgov_api. | ||
* | ||
* @SfgApi( | ||
* id = "paragraph_form_io", | ||
* title = @Translation("Paragraph form_io"), | ||
* bundle = "form_io", | ||
* wag_bundle = "form_io", | ||
* entity_id = {}, | ||
* langcode = {}, | ||
* ) | ||
*/ | ||
class FormIo extends SfgApiParagraphBase { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setCustomData($entity) { | ||
return [ | ||
'formio_data_source' => $entity->get('field_formio_data_source')->value, | ||
// @todo this plugin is incomplete | ||
// 'field_custom_form_strings' => $entity->get('field_custom_form_strings')->value, | ||
// 'field_form_strings' => $entity->get('field_form_strings')->value, | ||
// 'field_formio_confirmation_url' => $entity->get('field_formio_confirmation_url')->value, | ||
// 'field_formio_json_content' => $entity->get('field_formio_json_content')->value, | ||
// 'field_formio_page_layout' => $entity->get('field_formio_page_layout')->value, | ||
// 'field_formio_render_options' => $entity->get('field_formio_render_options')->value, | ||
// 'field_get_formio_strings' => $entity->get('field_get_formio_strings')->value, | ||
]; | ||
} | ||
|
||
} |
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