Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PXBF release v0.7.0.beta.1 #1988

Merged
merged 6 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ langcode: en
status: true
dependencies:
config:
- field.field.node.bears_life_event.field_b_display_order
- field.field.node.bears_life_event.field_b_id
- field.field.node.bears_life_event.field_b_search_title
- field.field.node.bears_life_event.field_draft_json_data_file
Expand Down Expand Up @@ -33,6 +34,13 @@ content:
region: content
settings: { }
third_party_settings: { }
field_b_display_order:
type: number
weight: 26
region: content
settings:
placeholder: ''
third_party_settings: { }
field_b_id:
type: string_textfield
weight: 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ langcode: en
status: true
dependencies:
config:
- field.field.node.bears_life_event.field_b_display_order
- field.field.node.bears_life_event.field_b_id
- field.field.node.bears_life_event.field_b_search_title
- field.field.node.bears_life_event.field_draft_json_data_file
Expand Down Expand Up @@ -30,6 +31,15 @@ content:
third_party_settings: { }
weight: -20
region: content
field_b_display_order:
type: number_integer
label: above
settings:
thousand_separator: ''
prefix_suffix: true
third_party_settings: { }
weight: 13
region: content
field_b_id:
type: string
label: above
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ status: true
dependencies:
config:
- core.entity_view_mode.node.teaser
- field.field.node.bears_life_event.field_b_display_order
- field.field.node.bears_life_event.field_b_id
- field.field.node.bears_life_event.field_b_search_title
- field.field.node.bears_life_event.field_draft_json_data_file
Expand Down Expand Up @@ -35,6 +36,7 @@ content:
weight: 100
region: content
hidden:
field_b_display_order: true
field_b_id: true
field_b_search_title: true
field_draft_json_data_file: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
uuid: 09004dc5-fcc7-4802-a64f-64629089ee4a
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_b_display_order
- node.type.bears_life_event
id: node.bears_life_event.field_b_display_order
field_name: field_b_display_order
entity_type: node
bundle: bears_life_event
label: 'Display Order'
description: 'The display order in benefit finder tool box of benefit finder landing page (https://www.usa.gov/benefit-finder)'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
min: null
max: null
prefix: ''
suffix: ''
field_type: integer
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ entity_type: paragraph
bundle: b_levent_relevant_benefit
label: Link
description: ''
required: false
required: true
translatable: false
default_value: { }
default_value_callback: ''
Expand Down
24 changes: 24 additions & 0 deletions config/sync/field.storage.node.field_b_display_order.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
uuid: ab4533d6-5920-4bba-9e8d-39269f7625d5
langcode: en
status: true
dependencies:
module:
- field_permissions
- node
third_party_settings:
field_permissions:
permission_type: public
id: node.field_b_display_order
field_name: field_b_display_order
entity_type: node
type: integer
settings:
unsigned: false
size: normal
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

namespace Drupal\usagov_benefit_finder_content\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\File\FileUrlGeneratorInterface;
use Drupal\file\FileRepositoryInterface;
use Drupal\usagov_benefit_finder\Traits\BenefitFinderTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* Class CheckDataController
* @package Drupal\usagov_benefit_finder_content\Controller
*/
class CheckDataController {
class CheckDataController extends ControllerBase {

use BenefitFinderTrait;

Expand Down Expand Up @@ -48,11 +56,11 @@ class CheckDataController {
protected $database;

/**
* Retrieves the currently active request object.
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\Request
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $request;
protected $requestStack;

/**
* The benefit finder content mode.
Expand All @@ -76,15 +84,49 @@ class CheckDataController {
protected $expanded;

/**
* Constructs a new LifeEventController object.
* Constructs a new CheckDataController object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system service.
* @param \Drupal\file\FileRepositoryInterface|null $file_repository
* The file repository.
* @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator
* The file URL generator.
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
*/
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
FileSystemInterface $file_system,
FileRepositoryInterface $file_repository,
FileUrlGeneratorInterface $file_url_generator,
Connection $database,
RequestStack $request_stack,
) {
$this->entityTypeManager = $entity_type_manager;
$this->fileSystem = $file_system;
$this->fileRepository = $file_repository;
$this->fileUrlGenerator = $file_url_generator;
$this->database = $database;
$this->requestStack = $request_stack;
}

/**
* {@inheritdoc}
*/
public function __construct() {
$this->entityTypeManager = \Drupal::service('entity_type.manager');
$this->fileSystem = \Drupal::service('file_system');
$this->fileRepository = \Drupal::service('file.repository');
$this->fileUrlGenerator = \Drupal::service('file_url_generator');
$this->database = \Drupal::service('database');
$this->request = \Drupal::request();
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity_type.manager'),
$container->get('file_system'),
$container->get('file.repository'),
$container->get('file_url_generator'),
$container->get('database'),
$container->get('request_stack'),
);
}

/**
Expand All @@ -95,12 +137,12 @@ public function checkData() {

// Get langcode.
if (empty($this->langcode)) {
$this->langcode = $this->request->get('langcode') ?? "en";
$this->langcode = $this->requestStack->getCurrentRequest()->query->get('langcode') ?? "en";
}

// Get expanded.
if (empty($this->expanded)) {
$this->expanded = $this->request->get('expanded') ?? "false";
$this->expanded = $this->requestStack->getCurrentRequest()->query->get('expanded') ?? "false";
}

$help = <<<EOD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,63 @@ function _usagov_benefit_finder_content_check_life_event_form_usage_in_life_even

return $return;
}

/**
* Implements hook_form_FORM_ID_alter().
*/
function usagov_benefit_finder_content_form_node_bears_benefit_delete_form_alter(array &$form, FormStateInterface $form_state) {
_usagov_benefit_finder_content_check_benefit_usage($form);
}

/**
* It checks benefit usage in life event forms and lists the life event forms.
*
* @param array $form
* Form array.
*/
function _usagov_benefit_finder_content_check_benefit_usage(array &$form) {
$description = '';

$node = \Drupal::routeMatch()->getParameter('node');
$nid = $node->id();

$result = _usagov_benefit_finder_content_check_benefit_usage_in_life_event_form($nid);
foreach ($result as $row) {
$description .= "<li>Life event form: $row[title] ($row[nid])</li>";
}

if (!empty($description)) {
$description = '<div class="entity-skip">'
. '<span>This benefit is used in following content:</span>'
. "<ul>$description</ul>"
. '</div>';
$form['description']['#markup'] = t($description);
}
}

/**
* It checks benefit usage in life event form.
*
* @param int $nid
* Node ID of given benefit.
* @return array
* An array of Node ID and title of life event forms.
*/
function _usagov_benefit_finder_content_check_benefit_usage_in_life_event_form(int $nid) {
$return = [];

$connection = Database::getConnection();

$query = $connection->select('node_field_data', 't1');
$query->join('node__field_b_life_event_forms', 't2', 't1.nid = t2.field_b_life_event_forms_target_id');
$query->fields('t1', ['title', 'nid']);
$query->condition('t2.entity_id', $nid);
$query->orderBy('title');
$result = $query->execute();

foreach ($result as $row) {
$return[] = ['nid' => $row->nid, 'title' => $row->title];
}

return $return;
}
Loading