diff --git a/.ddev/config.yaml b/.ddev/config.yaml new file mode 100644 index 000000000..c657b31a0 --- /dev/null +++ b/.ddev/config.yaml @@ -0,0 +1,20 @@ +name: drupalcz +type: drupal9 +docroot: docroot +php_version: "8.1" +webserver_type: apache-fpm +router_http_port: "80" +router_https_port: "443" +xdebug_enabled: false +additional_hostnames: [] +additional_fqdns: [] +database: + type: mariadb + version: "10.11" +use_dns_when_possible: true +composer_version: "2" +web_environment: [] + +hooks: + post-start: + - exec: scripts/create-settings.sh diff --git a/.gitignore b/.gitignore index f1497e372..5831ad19b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,14 @@ local.blt.yml .lando.local.yml /docroot/themes/custom/dcz_theme/config_local.json +# DDEV +.ddev/.homeadditions +.ddev/.gitignore +.ddev/import-db +.ddev/db_snapshots +.ddev/.dbirc +.ddev/.bash_history + # Ignore drupal core. docroot/core diff --git a/DDEV_MIGRATION.md b/DDEV_MIGRATION.md new file mode 100644 index 000000000..b7b450c34 --- /dev/null +++ b/DDEV_MIGRATION.md @@ -0,0 +1,167 @@ +# Migrating from Lando to DDEV + +This document explains how to migrate from Lando to DDEV for local development. + +## Prerequisites + +1. Install DDEV: https://ddev.readthedocs.io/en/stable/#installation +2. Stop and remove your Lando environment (optional, but recommended to free resources): + ``` + lando stop + lando destroy + ``` + +## Migration Steps + +### 1. Start DDEV + +```bash +ddev start +``` + +This will: +- Download required Docker images +- Create containers for web server, database, and other services +- Run the `scripts/create-settings.sh` hook to create local settings file + +### 2. Install Drupal + +If you're setting up from scratch: + +```bash +ddev drush si minimal --existing-config +``` + +### 3. Import Content (Optional) + +If you want default content for development: + +```bash +ddev drush dcdi --force update +ddev drush cr +``` + +### 4. Get Login Link + +```bash +ddev drush uli +``` + +### 5. Access Your Site + +Your site will be available at: +- http://drupalcz.ddev.site +- https://drupalcz.ddev.site (if mkcert is installed) + +## Useful DDEV Commands + +| Lando Command | DDEV Equivalent | +|---------------|-----------------| +| `lando start` | `ddev start` | +| `lando stop` | `ddev stop` | +| `lando poweroff` | `ddev poweroff` | +| `lando drush ` | `ddev drush ` | +| `lando composer ` | `ddev composer ` | +| `lando ssh` | `ddev ssh` | +| `lando db-import ` | `ddev import-db --src=` | +| `lando db-export` | `ddev export-db` | +| `lando logs` | `ddev logs` | + +## Database Migration + +If you have an existing database in Lando that you want to migrate: + +1. Export from Lando: + ```bash + lando db-export database.sql.gz + ``` + +2. Stop Lando and start DDEV: + ```bash + lando stop + ddev start + ``` + +3. Import into DDEV: + ```bash + ddev import-db --src=database.sql.gz + ddev drush cr + ``` + +## Files Migration + +If you have user-uploaded files: + +1. Your files in `docroot/sites/default/files/` will remain in place +2. Private files are now expected at `/var/www/html/private` inside the container + +## Frontend Development + +The original Lando setup included Node.js for theme development. For DDEV, you have two options: + +### Option 1: Use DDEV's Node service (Recommended) + +Add to `.ddev/config.yaml`: +```yaml +web_extra_daemons: + - name: "node" + command: "/var/www/html/docroot/themes/custom/dcz_theme && npm install && npm run watch" + directory: /var/www/html/docroot/themes/custom/dcz_theme +``` + +### Option 2: Use Node.js on your host machine + +Install Node.js locally and run: +```bash +cd docroot/themes/custom/dcz_theme +npm install +npm run watch +``` + +## Differences from Lando + +- **Database host**: Changed from `database` to `db` +- **Database credentials**: All are `db` (name, username, password) +- **Project URL**: Changed from `*.lndo.site` to `*.ddev.site` +- **Mailhog**: Available at http://drupalcz.ddev.site:8025 +- **PHP version**: 7.4 (same as Lando) +- **Web server**: Apache (same as Lando) + +## Custom Settings Structure + +This project uses a custom settings file structure instead of DDEV's default `settings.ddev.php`: + +1. **Main settings**: `docroot/sites/default/settings.php` includes `docroot/sites/default/settings/includes.settings.php` +2. **DDEV detection**: `includes.settings.php` detects DDEV via the `IS_DDEV_PROJECT` environment variable +3. **DDEV settings**: When DDEV is detected, it loads `docroot/sites/default/settings/ddev.settings.php` +4. **Local overrides**: Finally, it loads `docroot/sites/default/settings/local.settings.php` if it exists + +This structure allows the same codebase to work with Lando, DDEV, Acquia Cloud, and other environments without modification. + +## Troubleshooting + +### Clear cache if you have issues +```bash +ddev drush cr +``` + +### Restart DDEV +```bash +ddev restart +``` + +### Check DDEV status +```bash +ddev describe +``` + +### View logs +```bash +ddev logs +``` + +## Additional Resources + +- DDEV Documentation: https://ddev.readthedocs.io/ +- DDEV Drupal Quickstart: https://ddev.readthedocs.io/en/stable/users/quickstart/#drupal + diff --git a/DDEV_SETUP.md b/DDEV_SETUP.md new file mode 100644 index 000000000..02c928b6a --- /dev/null +++ b/DDEV_SETUP.md @@ -0,0 +1,82 @@ +# DDEV Migration Summary + +## Files Created + +1. **`.ddev/config.yaml`** - Main DDEV configuration file + - Configures Drupal 9, PHP 7.4, Apache, MariaDB 10.4 + - Disables DDEV's automatic settings management (we use custom structure) + - Includes post-start hook to create local settings file + +2. **`docroot/sites/default/settings/ddev.settings.php`** - DDEV-specific settings + - Database connection configuration (db/db/db on host 'db') + - Development-friendly settings (caching disabled, update access enabled) + - Config split configuration for development + - Private files path and other Drupal settings + +3. **`DDEV_MIGRATION.md`** - Migration guide + - Step-by-step instructions for migrating from Lando to DDEV + - Command reference table + - Database and files migration instructions + - Troubleshooting tips + +## Files Modified + +1. **`docroot/sites/default/settings/includes.settings.php`** + - Added DDEV environment detection using `IS_DDEV_PROJECT` environment variable + - Loads `settings/ddev.settings.php` when running in DDEV + +2. **`.gitignore`** + - Added DDEV-specific ignore patterns + +3. **`README.md`** + - Added DDEV setup instructions + - Added reference to migration guide + +## How It Works + +### Settings Loading Chain: +1. Drupal loads `docroot/sites/default/settings.php` +2. Which includes `docroot/sites/default/settings/includes.settings.php` +3. `includes.settings.php` checks for environment: + - If `IS_DDEV_PROJECT=true` → loads `settings/ddev.settings.php` + - If `LANDO_APP_NAME` exists → loads `settings/lando.settings.php` + - If `AH_SITE_ENVIRONMENT` exists → loads Acquia Cloud settings +4. Finally loads `settings/local.settings.php` for any local overrides + +### Database Configuration: +- **Host**: `db` (DDEV's database container) +- **Database**: `db` +- **Username**: `db` +- **Password**: `db` +- **Port**: `3306` + +This setup ensures that: +- Both Lando and DDEV can work simultaneously (different environment detection) +- No code changes needed when switching between environments +- Settings are organized and maintainable +- DDEV doesn't interfere with the custom settings structure + +## Quick Start + +```bash +# Start DDEV +ddev start + +# Check status +ddev drush status + +# Get login link +ddev drush uli + +# Access site at: +# http://drupalcz.ddev.site +``` + +## Note on settings.ddev.php + +DDEV normally auto-generates a `settings.ddev.php` file in `docroot/sites/default/`. +This project uses a custom settings structure, so we: +- Set `disable_settings_management: true` in `.ddev/config.yaml` +- Use `docroot/sites/default/settings/ddev.settings.php` instead +- This allows better organization and multi-environment support + diff --git a/README.md b/README.md index 4ffc60a28..644d7514b 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,22 @@ Branch | Build status | Dev site | HTTP Basic auth * .travis.yml - Travis CI test suite configuration. ## Requirements +### Pokud používáte DDEV +* Nainstalujte si DDEV, https://ddev.readthedocs.io/en/stable/#installation +* V adresáři projektu spusťte DDEV + + ddev start + +* Po prvním spuštění nainstalujte Drupal: + + ddev drush si minimal --existing-config + +* Přihlaste se: + + ddev drush uli + +* **Pokud migrujete z Lando**, viz [DDEV_MIGRATION.md](DDEV_MIGRATION.md) + ### Pokud používáte Lando * Nainstalujte si Lando, https://docs.devwithlando.io/installation/system-requirements.html * V adresáři projektu spusťte Lando diff --git a/docroot/modules/custom/slack_invite/config/install/slack_invite.settings.yml b/docroot/modules/custom/slack_invite/config/install/slack_invite.settings.yml new file mode 100644 index 000000000..96dfc4883 --- /dev/null +++ b/docroot/modules/custom/slack_invite/config/install/slack_invite.settings.yml @@ -0,0 +1,6 @@ +token: "" +hostname: "" +twostep: + enabled: FALSE + channel: "" + message: "!email has requested an invitation to the Slack team. Click the following link to approve: !url" diff --git a/docroot/modules/custom/slack_invite/slack_invite.info.yml b/docroot/modules/custom/slack_invite/slack_invite.info.yml new file mode 100644 index 000000000..8895a611a --- /dev/null +++ b/docroot/modules/custom/slack_invite/slack_invite.info.yml @@ -0,0 +1,6 @@ +name: Slack Invite +type: module +description: 'Invite your users to your slack team' +package: Custom +core_version_requirement: ^9 || ^10 || ^11 + diff --git a/docroot/modules/custom/slack_invite/slack_invite.links.menu.yml b/docroot/modules/custom/slack_invite/slack_invite.links.menu.yml new file mode 100644 index 000000000..4fde6ca0e --- /dev/null +++ b/docroot/modules/custom/slack_invite/slack_invite.links.menu.yml @@ -0,0 +1,5 @@ +slack_invite.settingss: + title: 'Slack Invite' + parent: system.admin_config_services + description: 'Slack Invite Settings' + route_name: slack_invite.settings diff --git a/docroot/modules/custom/slack_invite/slack_invite.module b/docroot/modules/custom/slack_invite/slack_invite.module new file mode 100644 index 000000000..1b4ee3e2f --- /dev/null +++ b/docroot/modules/custom/slack_invite/slack_invite.module @@ -0,0 +1,42 @@ + 1, + 'email' => $email, + 'set_active' => 'true', + 'token' => variable_get('slack_invite_token', ''), + ]; + + $data['channels'] = variable_get('slack_invite_channels', ''); + if (empty($data['channels'])) { + unset($data['channels']); + } + + $data = drupal_http_build_query($data); + $options = [ + 'method' => 'POST', + 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], + 'data' => $data, + ]; + + return drupal_http_request("{$api_url}", $options); +} diff --git a/docroot/modules/custom/slack_invite/slack_invite.permissions.yml b/docroot/modules/custom/slack_invite/slack_invite.permissions.yml new file mode 100644 index 000000000..47869f4a7 --- /dev/null +++ b/docroot/modules/custom/slack_invite/slack_invite.permissions.yml @@ -0,0 +1,7 @@ +administer slack invite: + title: 'Administer Slack Invite Settings.' + description: 'Administer the Slack Invite Settings.' + +approve slack invite: + title: 'Approve Slack Invites.' + description: 'Approve two-step Slack invitations.' diff --git a/docroot/modules/custom/slack_invite/slack_invite.routing.yml b/docroot/modules/custom/slack_invite/slack_invite.routing.yml new file mode 100644 index 000000000..b9e16fe59 --- /dev/null +++ b/docroot/modules/custom/slack_invite/slack_invite.routing.yml @@ -0,0 +1,15 @@ +slack_invite.settings: + path: '/admin/config/services/slack-invite' + defaults: + _form: 'Drupal\slack_invite\Form\SlackInviteSettingsForm' + _title: 'Slack Invite Settings' + requirements: + _permission: 'administer slack invite' + +slack_invite.twostep: + path: '/slack_invite/{email}/{token}' + defaults: + _form: 'Drupal\slack_invite\Form\SlackInviteTwoStepApproveForm' + _title: 'Approve Slack invitation' + requirements: + _custom_access: 'Drupal\slack_invite\Form\SlackInviteTwoStepApproveForm::access' diff --git a/docroot/modules/custom/slack_invite/slack_invite.services.yml b/docroot/modules/custom/slack_invite/slack_invite.services.yml new file mode 100644 index 000000000..389293e56 --- /dev/null +++ b/docroot/modules/custom/slack_invite/slack_invite.services.yml @@ -0,0 +1,3 @@ +services: + slack_invite: + class: Drupal\slack_invite\SlackInvite diff --git a/docroot/modules/custom/slack_invite/src/Form/SlackInviteForm.php b/docroot/modules/custom/slack_invite/src/Form/SlackInviteForm.php new file mode 100644 index 000000000..5fdcc0e8b --- /dev/null +++ b/docroot/modules/custom/slack_invite/src/Form/SlackInviteForm.php @@ -0,0 +1,68 @@ +config('slack_invite.settings'); + + $form['#action'] = Url::fromRoute('', ['query' => $this->getDestinationArray(), 'external' => FALSE])->toString(); + $form['slack_email'] = [ + '#type' => 'textfield', + '#title' => $this->t('Email'), + '#description' => $this->t('Enter email address for slack invite'), + '#required' => TRUE, + ]; + + $form['actions'] = [ + '#type' => 'actions', + ]; + $form['actions']['submit'] = [ + '#type' => 'submit', + '#value' => $this->t('Send') + ]; + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, FormStateInterface $form_state) { + $email = $form_state->getValue('slack_email'); + if (!\Drupal::service('email.validator')->isValid($email)) { + $form_state->setErrorByName('slack_email', $this->t('Enter email address in valid format (ex. example@example.com)')); + } + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $slack_invite = \Drupal::service('slack_invite'); + $slack_invite->send($form_state->getValue('slack_email')); + } +} diff --git a/docroot/modules/custom/slack_invite/src/Form/SlackInviteSettingsForm.php b/docroot/modules/custom/slack_invite/src/Form/SlackInviteSettingsForm.php new file mode 100644 index 000000000..d9801ec63 --- /dev/null +++ b/docroot/modules/custom/slack_invite/src/Form/SlackInviteSettingsForm.php @@ -0,0 +1,166 @@ +config('slack_invite.settings'); + + $form['slack_invite_token'] = [ + '#type' => 'textfield', + '#title' => $this->t('Slack Web API Token'), + '#description' => $this->t("Enter the Web API token you get from your team domain. Please ensure that the token has the required 'admin' scope to send out email invites."), + '#default_value' => $config->get('token'), + '#required' => TRUE, + ]; + + $form['slack_invite_hostname'] = [ + '#type' => 'textfield', + '#title' => $this->t('Slack Domain Hostname'), + '#description' => $this->t('Enter your slack team domain (ex. if your domain is https://drupal.slack.com, you would enter "drupal" minus the quotations).'), + '#default_value' => $config->get('hostname'), + '#required' => TRUE, + ]; + + $form['slack_bypass_check'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Bypass credential check'), + '#description' => $this->t('Bypass checking that token and hostname combination are valid'), + ]; + + $form['slack_twostep'] = [ + '#type' => 'details', + '#title' => $this->t('Two-step approval'), + '#open' => TRUE, + '#tree' => TRUE, + ]; + + $twostep = $config->get('twostep'); + $form['slack_twostep']['enabled'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Enable two-step approval'), + '#default_value' => $twostep['enabled'], + ]; + + $form['slack_twostep']['channel'] = [ + '#type' => 'textfield', + '#title' => $this->t('Channel'), + '#description' => $this->t('A slack channel name or id in which the invitation approval request will be sent'), + '#default_value' => $twostep['channel'], + '#states' => [ + 'invisible' => [ + ':input[name="slack_twostep[enabled]"]' => ['checked' => FALSE], + ], + ], + ]; + + $form['slack_twostep']['message'] = [ + '#type' => 'textfield', + '#title' => $this->t('Message'), + '#description' => $this->t('A message to sent to the above channel'), + '#default_value' => $twostep['message'], + '#states' => [ + 'invisible' => [ + ':input[name="slack_twostep[enabled]"]' => ['checked' => FALSE], + ], + ], + ]; + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, FormStateInterface $form_state) { + if ($form_state->getValue('slack_twostep')['enabled']) { + // Validate channel. + if (empty($form_state->getValue('slack_twostep')['channel'])) { + $form_state->setError($form['slack_twostep']['channel'], $this->t('Channel field is required when two-step approval is enabled.')); + } + + // Validate message. + if (empty($form_state->getValue('slack_twostep')['message'])) { + $form_state->setError($form['slack_twostep']['message'], $this->t('Message field is required when two-step approval is enabled.')); + } + } + + if ($form_state->getValue('slack_bypass_check')) { + return; + } + $team_hostname = $form_state->getValue('slack_invite_hostname'); + $token = $form_state->getValue('slack_invite_token'); + $api_url = "https://{$team_hostname}.slack.com/api/api.test"; + + $data = [ + 'form_params' => [ + '_attempts' => 1, + 'token' => $token, + ], + ]; + + try { + $client = \Drupal::httpClient(); + $response = $client->request('POST', $api_url, $data); + // Expected result. + $response_data = json_decode('' . $response->getBody()); + if ($response_data->ok !== TRUE) { + throw new Exception($this->t('Please check the token and hostname; unable to test request')); + } + // Ensure the correct scope is set. + if ($response->hasHeader('x-oauth-scopes')) { + $scopes = explode(',', $response->getHeader('x-oauth-scopes')[0]); + if (!in_array('admin', $scopes)) { + throw new Exception($this->t('The supplied token is missing the required scope: admin')); + } + } + } + catch (Exception $e) { + $form_state->setErrorByName('slack_invite_token', $e->getMessage()); + } + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $values = $form_state->getValues(); + + $config = $this->config('slack_invite.settings'); + $config->set('token', $values['slack_invite_token']) + ->set('hostname', $values['slack_invite_hostname']) + ->set('twostep', $values['slack_twostep']) + ->save(); + parent::submitForm($form, $form_state); + } + +} diff --git a/docroot/modules/custom/slack_invite/src/Form/SlackInviteTwoStepApproveForm.php b/docroot/modules/custom/slack_invite/src/Form/SlackInviteTwoStepApproveForm.php new file mode 100644 index 000000000..fb05c6323 --- /dev/null +++ b/docroot/modules/custom/slack_invite/src/Form/SlackInviteTwoStepApproveForm.php @@ -0,0 +1,72 @@ +email = \Drupal::routeMatch()->getParameter('email'); + $this->token = \Drupal::routeMatch()->getParameter('token'); + } + + /** + * Access check for form route. + */ + public function access(AccountInterface $account) { + $permission = $account->hasPermission('approve slack invite'); + + $slack_invite = \Drupal::service('slack_invite'); + $token = $this->token == $slack_invite->getEmailToken($this->email); + + return AccessResult::allowedIf($permission && $token); + } + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'slack_invite_twostep_approve_form'; + } + + /** + * @inheritdoc + */ + public function getCancelUrl() { + return Url::fromRoute(''); + } + + /** + * @inheritdoc + */ + public function getQuestion() { + return $this->t('Are you sure you want to invite %email to the Slack team?', ['%email' => $this->email]); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $slack_invite = \Drupal::service('slack_invite'); + $slack_invite->send(\Drupal::routeMatch()->getParameter('email'), TRUE); + $form_state->setRedirectUrl($this->getCancelUrl()); + } +} diff --git a/docroot/modules/custom/slack_invite/src/Plugin/Block/SlackInviteFormBlock.php b/docroot/modules/custom/slack_invite/src/Plugin/Block/SlackInviteFormBlock.php new file mode 100644 index 000000000..f186920eb --- /dev/null +++ b/docroot/modules/custom/slack_invite/src/Plugin/Block/SlackInviteFormBlock.php @@ -0,0 +1,30 @@ +getForm('Drupal\slack_invite\Form\SlackInviteForm'); + } + +} diff --git a/docroot/modules/custom/slack_invite/src/SlackInvite.php b/docroot/modules/custom/slack_invite/src/SlackInvite.php new file mode 100644 index 000000000..8c5018bba --- /dev/null +++ b/docroot/modules/custom/slack_invite/src/SlackInvite.php @@ -0,0 +1,172 @@ +email = $email; + $this->config = \Drupal::config('slack_invite.settings'); + $method = !$this->config->get('twostep')['enabled'] ? 'sendDirect' : 'sendTwoStep'; + if ($direct == TRUE) { + $method = 'sendDirect'; + } + call_user_func([$this, $method]); + } + + /** + * Send the invite directly to the user. + */ + protected function sendDirect() { + $team_hostname = $this->config->get('hostname'); + $api_url = "https://{$team_hostname}.slack.com/api/users.admin.invite?t=" . time(); + + $data = [ + 'form_params' => [ + '_attempts' => 1, + 'email' => $this->email, + 'set_active' => 'true', + 'token' => $this->config->get('token'), + ], + ]; + + try { + $client = \Drupal::httpClient(); + $response = $client->request('POST', $api_url, $data); + + $response_data = json_decode('' . $response->getBody()); + if ($response_data->ok == TRUE) { + \Drupal::messenger()->addStatus(t('You will receive an email notification inviting you to join the slack team shortly.')); + } + else { + $message = ''; + switch ($response_data->error) { + case SLACK_INVITE_ALREADY_IN_TEAM: + $message = $this->t('The user is already a member of the team'); + break; + + case SLACK_INVITE_SENT_RECENTLY: + $message = $this->t('The user was recently sent an invitation.'); + break; + + case SLACK_INVITE_ALREADY_INVITED: + $message = $this->t('The user is already invited.'); + break; + + default: + $message = $data['error']; + break; + } + \Drupal::messenger()->addStatus($this->t('There was an error sending your invite. Please contact the administrator with the following error details. The error message from slack was: @message', ['@message' => $message])); + } + } + catch (Exception $e) { + \Drupal::messenger()->addError($this->t('Something went wrong with the request. Please contact site administrator.')); + } + } + + /** + * Send a two-step request for invitation to the designated Slack channel. + */ + protected function sendTwoStep() { + $token = $this->getEmailToken($this->email); + $url = Url::fromRoute('slack_invite.twostep', [ + 'email' => $this->email, + 'token' => $token, + ], ['absolute' => TRUE]); + $url = $url->toString(); + + $team_hostname = $this->config->get('hostname'); + $api_url = "https://{$team_hostname}.slack.com/api/chat.postMessage?t=" . time(); + + $message = $this->t($this->config->get('twostep')['message'], [ + '!email' => $this->email, + '!url' => $url, + ]); + + $data = [ + 'form_params' => [ + '_attempts' => 1, + 'token' => $this->config->get('token'), + 'channel' => $this->config->get('twostep')['channel'], + 'text' => $message->render(), + ], + ]; + + try { + $client = \Drupal::httpClient(); + $response = $client->request('POST', $api_url, $data); + + $response_data = json_decode('' . $response->getBody()); + if ($response_data->ok == TRUE) { + \Drupal::messenger()->addStatus($this->t('Your slack invitation request has been made and you will receive an email notification inviting you to join the slack team pending approval.')); + } + else { + $message = ''; + switch ($response_data->error) { + default: + $message = $data['error']; + break; + } + \Drupal::messenger()->addStatus($this->t('There was an error sending your invitation request. Please contact the administrator with the following error details. The error message from slack was: @message', ['@message' => $message])); + } + } + catch (Exception $e) { + \Drupal::messenger()->addError($this->t('Something went wrong with the request. Please contact site administrator.')); + } + } + + /** + * @param $email + * @return string + */ + public function getEmailToken($email) { + // Return the first 8 characters. + return substr(Crypt::hmacBase64($email, $this->getPrivateKey() . $this->getHashSalt()), 0, 8); + } + + /** + * Gets the Drupal private key. + * + * @return string + * The Drupal private key. + */ + protected function getPrivateKey() { + return \Drupal::service('private_key')->get(); + } + + /** + * Gets a salt useful for hardening against SQL injection. + * + * @return string + * A salt based on information in settings.php, not in the database. + * + * @throws \RuntimeException + */ + protected function getHashSalt() { + return Settings::getHashSalt(); + } +} diff --git a/docroot/sites/default/settings.php b/docroot/sites/default/settings.php index 1b1291be9..ae556e64b 100644 --- a/docroot/sites/default/settings.php +++ b/docroot/sites/default/settings.php @@ -6,3 +6,12 @@ */ require_once DRUPAL_ROOT . "/sites/default/settings/includes.settings.php"; + +// Automatically generated include for settings managed by ddev. +$ddev_settings = __DIR__ . '/settings.ddev.php'; +if (getenv('IS_DDEV_PROJECT') == 'true' && is_readable($ddev_settings)) { + require $ddev_settings; +} + +// WTF, without this here it doesnt work.. to be fixed! +$settings['config_sync_directory'] = "../config/default"; diff --git a/docroot/sites/default/settings/ddev.settings.php b/docroot/sites/default/settings/ddev.settings.php new file mode 100644 index 000000000..9c1726384 --- /dev/null +++ b/docroot/sites/default/settings/ddev.settings.php @@ -0,0 +1,92 @@ + + [ + 'default' => + [ + 'database' => $loc_db_name, + 'username' => $loc_db_user, + 'password' => $loc_db_pass, + 'host' => $loc_db_host, + 'port' => $loc_db_port, + 'driver' => 'mysql', + 'prefix' => '', + ], + ], +]; + +/** + * Setup files on local. + */ +$settings['file_public_path'] = "sites/default/files"; +$settings['file_private_path'] = "/var/www/html/private"; +$settings["file_temp_path"] = '/tmp'; + +/** + * Skip file system permissions hardening on local. + */ +$settings['skip_permissions_hardening'] = TRUE; + +/** + * Access control for update.php script. + */ +$settings['update_free_access'] = TRUE; + +/** + * Enable local development services. + */ +$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml'; + +/** + * Disable Drupal caching. + */ +$settings['cache']['bins']['render'] = 'cache.backend.null'; +$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null'; + +/** + * Enable access to rebuild.php. + */ +$settings['rebuild_access'] = TRUE; + +/** + * Salt for one-time login links, cancel links, form tokens, etc. + */ +$settings['hash_salt'] = 'LOCAL_ONLY'; + +/** + * Simulate config we have available on Acquia. + * + * Get your own keys: + * * Slack token: https://api.slack.com/custom-integrations/legacy-tokens . + */ +$config['slack_invite.settings']['token'] = "DUMMY_TOKEN"; + +/** + * Set active config split. + */ +$config['config_split.config_split.default_content']['status'] = TRUE; +$config['config_split.config_split.dev']['status'] = TRUE; +$config['config_split.config_split.test']['status'] = FALSE; +$config['config_split.config_split.cleantalk']['status'] = FALSE; +$config['config_split.config_split.prod']['status'] = FALSE; + +/** + * Trusted host patterns for DDEV. + */ +$settings['trusted_host_patterns'] = [ + '^localhost$', + '^drupalcz\.ddev\.site$', +]; + diff --git a/docroot/sites/default/settings/includes.settings.php b/docroot/sites/default/settings/includes.settings.php index b1c309a47..5beaa3931 100644 --- a/docroot/sites/default/settings/includes.settings.php +++ b/docroot/sites/default/settings/includes.settings.php @@ -139,6 +139,17 @@ } } +/** + * DDEV environment settings. + */ +if (getenv('IS_DDEV_PROJECT') == 'true') { + $path = DRUPAL_ROOT . "/sites/default/settings/ddev.settings.php"; + // Load settings. + if (!empty($path) && file_exists($path)) { + //require $path; + } +} + /** * Allow final local override. */ diff --git a/private/.htaccess b/private/.htaccess new file mode 100644 index 000000000..d43687965 --- /dev/null +++ b/private/.htaccess @@ -0,0 +1,27 @@ +# Deny all requests from Apache 2.4+. + + Require all denied + + +# Deny all requests from Apache 2.0-2.2. + + Deny from all + + +# Turn off all options we don't need. +Options -Indexes -ExecCGI -Includes -MultiViews + +# Set the catch-all handler to prevent scripts from being executed. +SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006 + + # Override the handler again if we're run later in the evaluation list. + SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003 + + +# If we know how to do it safely, disable the PHP engine entirely. + + php_flag engine off + + + php_flag engine off + \ No newline at end of file