Skip to content

Commit

Permalink
Merge branch 'dev' into USAGOV-2132-hide-contact-info-by-page
Browse files Browse the repository at this point in the history
  • Loading branch information
whitealbum authored Jan 28, 2025
2 parents 66e4282 + aef8bd5 commit 6828416
Show file tree
Hide file tree
Showing 22 changed files with 203 additions and 128 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ submitting a pull request.
[back to top](#usagov-2021)
## Checking PHP dode style and syntax errors
## Checking PHP code style and syntax errors
PHPCodesniffer and the parallel linting tools should be installed automatically on a local environment via `composer install`. PHPCodeSniffer is used to ensure new code follows Drupal's coding standard. The parallel linter will check for PHP syntax errors. If they detect any errors, they must be fixed before a PR of changes can be accepted.
The following composer scripts are aliases for running these tools.
Expand All @@ -264,8 +264,12 @@ It's defined as a dev dependency in `composer.json` and will be installed automa
The following composer scripts are aliases for running PHPStan
* Check for errors at the level configured in `phpstan.neon`
`./bin/composer phpcs-errors`:
* Check for errors at the level configured in `phpstan.neon`:
`./bin/composer phpstan`
(optionally, supply a file or directory name starting with `web/`)
## Project restart/reset
Sometimes, Docker problems arise after an upgrade and a more complete restart is needed. After closing down and
Expand Down
3 changes: 1 addition & 2 deletions bin/cloudgov/db-portforward
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ cf create-service-key database db-portforward >/dev/null 2>&1
echo "Collecting connection info"
CF_APP_GUID=$(cf app cms --guid)
CF_PROCESS_GUID=`cf curl /v3/apps/${CF_APP_GUID}/processes | jq --raw-output '.resources | .[] | select(.type == "web").guid'`
CF_INFO=$(cf curl /v2/info)
CF_DB_INFO=$(cf service-key database db-portforward)
CF_DB_PORT=$(echo "$CF_DB_INFO" | grep '"port":' | sed 's/.*"port": "\([^"]*\)".*/\1/')
CF_DB_HOST=$(echo "$CF_DB_INFO" | grep '"host":' | sed 's/.*"host": "\([^"]*\)".*/\1/')
CF_DB_USER=$(echo "$CF_DB_INFO" | grep '"username":' | sed 's/.*"username": "\([^"]*\)".*/\1/')
CF_DB_PASS=$(echo "$CF_DB_INFO" | grep '"password":' | sed 's/.*"password": "\([^"]*\)".*/\1/')
CF_DB_NAME=$(echo "$CF_DB_INFO" | grep '"db_name":' | sed 's/.*"db_name": "\([^"]*\)".*/\1/')
CF_SSH_ENDPOINT=$(echo "$CF_INFO" | grep '"app_ssh_endpoint":' | sed 's/.*"app_ssh_endpoint": "\([^:]*\).*".*/\1/')
CF_SSH_ENDPOINT=`cf curl / | jq -r '.links.app_ssh.href | split(":")[0]'`

echo "Creating sql connection"
nohup sshpass -p $(cf ssh-code) ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -4 -N -p 2222 -L $LOCAL_PORT:$CF_DB_HOST:$CF_DB_PORT cf:$CF_PROCESS_GUID/0@$CF_SSH_ENDPOINT >/dev/null 2>&1 &
Expand Down
20 changes: 10 additions & 10 deletions bin/cloudgov/deploy-services
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ generate_string()
generate_cert_json()
{
if command -v openssl >/dev/null ; then
SECAUTHSECRETS=$(cf curl /v2/user_provided_service_instances/$(cf service secauthsecrets --guid) | jq -r '.entity | select(.name == "secauthsecrets") | .credentials' )
SECAUTHSECRETS=$(cf curl /v3/service_instances/$(cf service secauthsecrets --guid)/credentials)
SP_KEY=$(echo -E "$SECAUTHSECRETS" | jq -r '.spkey')
SP_CRT=$(echo -E "$SECAUTHSECRETS" | jq -r '.spcrt')

Expand Down Expand Up @@ -141,15 +141,15 @@ generate_cert_json()
echo "Configuring Secrets Service"
if service_exists "secrets" ; then
echo "secrets already created: updating"
CURR_SECRETS=$(cf curl /v2/user_provided_service_instances/$(cf service secrets --guid))
CURR_CRON_KEY=$(echo $CURR_SECRETS | jq -r '.entity.credentials.CRON_KEY')
CURR_HASH_SALT=$(echo $CURR_SECRETS | jq -r '.entity.credentials.HASH_SALT')
CURR_ROOT_USER_NAME=$(echo $CURR_SECRETS | jq -r '.entity.credentials.ROOT_USER_NAME')
CURR_ROOT_USER_PASS=$(echo $CURR_SECRETS | jq -r '.entity.credentials.ROOT_USER_PASS')
CURR_NEW_RELIC_DISPLAY_NAME=$(echo $CURR_SECRETS | jq -r '.entity.credentials.NEW_RELIC_DISPLAY_NAME')
CURR_NEW_RELIC_APP_NAME=$(echo $CURR_SECRETS | jq -r '.entity.credentials.NEW_RELIC_APP_NAME')
CURR_NEW_RELIC_LICENSE_KEY=$(echo $CURR_SECRETS | jq -r '.entity.credentials.NEW_RELIC_LICENSE_KEY')
CURR_NEW_RELIC_API_KEY=$(echo $CURR_SECRETS | jq -r '.entity.credentials.NEW_RELIC_API_KEY')
CURR_SECRETS=$(cf curl /v3/service_instances/$(cf service secrets --guid)/credentials)
CURR_CRON_KEY=$(echo $CURR_SECRETS | jq -r '.CRON_KEY')
CURR_HASH_SALT=$(echo $CURR_SECRETS | jq -r '.HASH_SALT')
CURR_ROOT_USER_NAME=$(echo $CURR_SECRETS | jq -r '.ROOT_USER_NAME')
CURR_ROOT_USER_PASS=$(echo $CURR_SECRETS | jq -r '.ROOT_USER_PASS')
CURR_NEW_RELIC_DISPLAY_NAME=$(echo $CURR_SECRETS | jq -r '.NEW_RELIC_DISPLAY_NAME')
CURR_NEW_RELIC_APP_NAME=$(echo $CURR_SECRETS | jq -r '.NEW_RELIC_APP_NAME')
CURR_NEW_RELIC_LICENSE_KEY=$(echo $CURR_SECRETS | jq -r '.NEW_RELIC_LICENSE_KEY')
CURR_NEW_RELIC_API_KEY=$(echo $CURR_SECRETS | jq -r '.NEW_RELIC_API_KEY')
if [ -n "$NEW_RELIC_DISPLAY_NAME" ]; then
CURR_NEW_RELIC_DISPLAY_NAME=${NEW_RELIC_DISPLAY_NAME}
fi
Expand Down
2 changes: 1 addition & 1 deletion bin/cloudgov/gsaauth-filegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ -z "$SPACE" ]; then
exit 1
fi;

SECAUTHSECRETS=$(cf curl /v2/user_provided_service_instances/$(cf service secauthsecrets --guid) | jq -r '.entity | select(.name == "secauthsecrets") | .credentials' )
SECAUTHSECRETS=$(cf curl /v3/service_instances/$(cf service secauthsecrets --guid)/credentials)
SP_KEY=$(echo -E "$SECAUTHSECRETS" | jq -r '.spkey')
SP_CRT=$(echo -E "$SECAUTHSECRETS" | jq -r '.spcrt')

Expand Down
2 changes: 1 addition & 1 deletion bin/cloudgov/scp-from
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ instance_index=${4:-0}
# https://cloud.gov/knowledge-base/2021-05-17-troubleshooting-ssh-connections/#changes-to-your-app-in-the-capi
# We need the PROCESS_GUID for the "web process" for our app.
echo "getting ssh_host"
ssh_host=`cf curl /v2/info | jq .app_ssh_endpoint | awk -F : '{print $1}' | sed 's/\"//g'`
ssh_host=`cf curl / | jq -r '.links.app_ssh.href | split(":")[0]'`

echo "getting app_guid"
app_guid=`cf env ${app_name} | grep application_id | awk '{print $2}' | sed 's/\"//g' | sed 's/,//g'`
Expand Down
2 changes: 1 addition & 1 deletion bin/cloudgov/scp-to
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ instance_index=${4:-0}
# https://cloud.gov/knowledge-base/2021-05-17-troubleshooting-ssh-connections/#changes-to-your-app-in-the-capi
# We need the PROCESS_GUID for the "web process" for our app.
echo "getting ssh_host"
ssh_host=`cf curl /v2/info | jq .app_ssh_endpoint | awk -F : '{print $1}' | sed 's/\"//g'`
ssh_host=`cf curl / | jq -r '.links.app_ssh.href | split(":")[0]'`

echo "getting app_guid"
app_guid=`cf env ${app_name} | grep application_id | awk '{print $2}' | sed 's/\"//g' | sed 's/,//g'`
Expand Down
4 changes: 2 additions & 2 deletions bin/snapshot-backups/old-db-pull-docker.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/bin/bash

CF_SVC_USER=$1
CF_SVC_PASS=$2
Expand All @@ -12,7 +13,6 @@ cf login -a https://api.fr.cloud.gov -u $CF_SVC_USER -p $CF_SVC_PASS
echo "[INFO] Creating access keys"
cf create-service-key database db-dump >/dev/null 2>&1
CF_GUID=$(cf app cms --guid)
CF_INFO=$(cf curl /v2/info)
CF_DB_INFO=$(cf service-key database db-dump)

CF_DB_PORT=$(echo "$CF_DB_INFO" | grep '"port":' | sed 's/.*"port": "\([^"]*\)".*/\1/')
Expand All @@ -21,7 +21,7 @@ CF_DB_USER=$(echo "$CF_DB_INFO" | grep '"username":' | sed 's/.*"username": "\([
CF_DB_PASS=$(echo "$CF_DB_INFO" | grep '"password":' | sed 's/.*"password": "\([^"]*\)".*/\1/')
CF_DB_NAME=$(echo "$CF_DB_INFO" | grep '"db_name":' | sed 's/.*"db_name": "\([^"]*\)".*/\1/')

CF_SSH_ENDPOINT=$(echo "$CF_INFO" | grep '"app_ssh_endpoint":' | sed 's/.*"app_ssh_endpoint": "\([^:]*\).*".*/\1/')
CF_SSH_ENDPOINT=`cf curl / | jq -r '.links.app_ssh.href | split(":")[0]'`
CF_SSH_CODE=$(cf ssh-code)

echo "[INFO] Creating local sql connection"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ public function __construct(
private SystemManager $systemManager,
) {}

// Returns a page with some instructions and the same list of links as are in the menu.
public function mainPage() {

/**
* Returns a page with some instructions and the same list of links as are in the menu.
*
* @return array<string, mixed>
*/
public function mainPage(): array {
// Loosely based on Drupal\system\Controller\SystemController::overview.
// That function assumes links will have blocks associated with them, which is not the case
// when we have provided a URL-based link instead of a route.
Expand Down
13 changes: 11 additions & 2 deletions web/modules/custom/usa_admin_styles/usa_admin_styles.module
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@

use Drupal\Core\Form\FormStateInterface;

function usa_admin_styles_preprocess_page(&$variables) {
/**
* Implements hook_preprocess_HOOK() for page templates.
*
* Attaches the mylib library to all admin pages.
*
* @param array<string, mixed> $variables
*/
function usa_admin_styles_preprocess_page(array &$variables): void {
$variables['#attached']['library'][] = 'usa_admin_styles/mylib';
}

/**
* Attaches a library to only the node forms. This covers the add and edit forms for nodes.
*
* @param array<string, mixed> $form
*/
function usa_admin_styles_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
function usa_admin_styles_form_node_form_alter(array &$form, FormStateInterface $form_state, string $form_id): void {
// The accordionButtonSubmitFix library suppresses form submit events from accordion buttons in
// rich text editor previews. This was not an issue with ckeditor 4 (which implemented previews
// in an iframe), but is a problem in ckeditor 5 -- all preview content is within the node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ use Drupal\user\Entity\User;

/**
* Update the content notification logic.
*
* @param array<string, mixed> $message
*/
function usa_content_moderation_notifications_mail_alter(&$message) {
function usa_content_moderation_notifications_mail_alter(array &$message): void {
$currentuser = User::load(\Drupal::currentUser()->id());
$hasPermission = $currentuser->hasPermission('Self content notification');
$message['to'] = \Drupal::config('system.site')->get('mail');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ public function getFormId(): string {

/**
* {@inheritdoc}
*
* @param array<string, mixed> $form
* @return array<string, mixed>
*/
#[\Override]
public function buildForm(array $form, FormStateInterface $form_state): array {
$form['#attached']['library'][] = 'usa_orphaned_entities/orphaned';
$form = parent::buildForm($form, $form_state);
Expand Down Expand Up @@ -94,9 +96,10 @@ public function buildForm(array $form, FormStateInterface $form_state): array {

/**
* {@inheritdoc}
*
* @param array<string, mixed> $form
*/
#[\Override]
public function validateForm(array &$form, FormStateInterface $form_state) {
public function validateForm(array &$form, FormStateInterface $form_state): void {
// foreach ($form['#entity_reference'] as $index => $entity_reference) {

// if (!str_contains($index, '#')) {
Expand All @@ -114,8 +117,10 @@ public function validateForm(array &$form, FormStateInterface $form_state) {

/**
* {@inheritdoc}
*
* @param array<string, mixed> $form
* @param-out array<mixed> $form
*/
#[\Override]
public function submitForm(array &$form, FormStateInterface $form_state): void {
$config = $this->config('orphaned_entities.settings');
foreach ($form['#entity_reference'] as $index => $entity_reference) {
Expand All @@ -138,8 +143,10 @@ public function submitForm(array &$form, FormStateInterface $form_state): void {

/**
* {@inheritdoc}
*
* @return array<string>
*/
protected function getEditableConfigNames() {
protected function getEditableConfigNames(): array {
return [
'orphaned_entities.settings',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
use Drupal\Component\Utility\Html;
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityInterface;

/**
* Implements hook_form_alter.
*/
*
* @param array<string, mixed> $form
**/

function usa_orphaned_entities_form_alter(&$form, &$form_state, $form_id) {
function usa_orphaned_entities_form_alter(array &$form, FormStateInterface &$form_state, string $form_id): void {
if (str_contains($form_id, 'delete_form')) {
// This is called on all delete form alters. Ensure we can get
// an entity otherwise bail early.
Expand All @@ -23,16 +27,15 @@ function usa_orphaned_entities_form_alter(&$form, &$form_state, $form_id) {
return;
}

$entity = $form_state->getFormObject()?->getEntity();
$entity = $delForm->getEntity();
if (!$entity) {
return;
}

$reference_data = usa_orphaned_entities_get_reference_data($entity);

$markup = "<div class=\"default-message\">" .
$form_state->getFormObject()->getDescription() .
"</div>";
$entity->getDescription() . "</div>";
$segway = "T"; // it's a joke about powered scooters
$additional = "";

Expand Down Expand Up @@ -116,7 +119,7 @@ function usa_orphaned_entities_form_alter(&$form, &$form_state, $form_id) {
/**
* Implements hook_entity_predelete.
*/
function usa_orphaned_entities_entity_predelete($entity) {
function usa_orphaned_entities_entity_predelete(EntityInterface $entity): void {
$reference_data = usa_orphaned_entities_get_reference_data($entity);
if (!empty($reference_data)) {
if (!empty($reference_data['delete'])) {
Expand All @@ -135,7 +138,12 @@ function usa_orphaned_entities_entity_predelete($entity) {

}

function usa_orphaned_entities_get_reference_data($deleting_entity) {
/**
* Grab the data from all references from the entity being deleted.
*
* @return array<string, mixed>
**/
function usa_orphaned_entities_get_reference_data(EntityInterface $deleting_entity): array {
$entityTypeManager = \Drupal::service('entity_type.manager');
$config = \Drupal::config('orphaned_entities.settings');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
namespace Drupal\usa_twig_vars\Event;

use Drupal\Component\EventDispatcher\Event;
// phpcs:ignore
use Drupal\usa_twig_vars\TaxonomyDatalayerBuilder;


/**
* @phpstan-import-type TaxonomyBreadcrumb from TaxonomyDatalayerBuilder
*/
class DatalayerAlterEvent extends Event {
const EVENT_NAME = 'usa_twig_vars.datalayer_alter';

/**
* @param TaxonomyBreadcrumb $datalayer
*/
public function __construct(
public array $datalayer,
) {}
Expand Down
Loading

0 comments on commit 6828416

Please sign in to comment.