Comments

tim.plunkett created an issue. See original summary.

srdtwc’s picture

Status: Active » Needs review
StatusFileSize
new4.73 KB

Added functionality to create a list of states to exclude from being logged. Based off of code from the config_log module.

tim.plunkett’s picture

Looks good!

  1. +++ b/src/Form/StateLogConfigForm.php
    @@ -0,0 +1,80 @@
    +   * Sate Log configuration form submit handler.
    

    s/Sate/State

  2. +++ b/src/StateLog.php
    @@ -94,6 +94,26 @@ class StateLog implements StateInterface {
    +   * @param $state_name
    

    string?

  3. +++ b/src/StateLog.php
    @@ -94,6 +94,26 @@ class StateLog implements StateInterface {
    +    $ignored_entities = \Drupal::config('state_log.settings')->get('log_ignored_state');
    +    if (!empty($ignored_entities)) {
    +      foreach ($ignored_entities as $ignore) {
    

    If you put ?: [] at the end of the first line, then you can skip the !empty check and just foreach it

  4. +++ b/src/StateLog.php
    @@ -103,11 +123,15 @@ class StateLog implements StateInterface {
    +      if($this->isKeyIgnored($key) != true){
    

    This looks indented oddly. Also, this line can be

    if (!$this->isKeyIgnored($key)) {
    
srdtwc’s picture

StatusFileSize
new4.67 KB

Here's a revised patch.

srdtwc’s picture

Can this be merged in? Thanks

tim.plunkett’s picture

A couple more points of feedback, but it's close!

  1. +++ b/schema/state_log.schema.yml
    @@ -0,0 +1,9 @@
    +        type: string
    \ No newline at end of file
    

    Needs a proper line ending

  2. +++ b/src/Form/StateLogConfigForm.php
    @@ -0,0 +1,80 @@
    + * Implements a StateLogConfig form.
    

    Configure State Log settings.

  3. +++ b/src/Form/StateLogConfigForm.php
    @@ -0,0 +1,80 @@
    +   * State Log configuration form.
    +   *
    ...
    +   * State Log configuration form submit handler.
    +   *
    

    These can be removed

  4. +++ b/src/Form/StateLogConfigForm.php
    @@ -0,0 +1,80 @@
    +Examples: <ul>
    +<li>system.theme.files</li>
    +<li>drupal_css_cache_files</li>
    +<li>system.maintenance_mode</li>
    +</ul>
    +
    +More documentation on the State API can be found here: <a target="_blank" href="https://www.drupal.org/docs/8/api/state-api/overview">https://www.drupal.org/docs/8/api/state-api/overview</a>
    +'
    +);
    

    This can be indented normally and have '); on the same line, it won't affect the visual formatting

  5. +++ b/src/Form/StateLogConfigForm.php
    @@ -0,0 +1,80 @@
    +    $form['submit'] = [
    +      '#type' => 'submit',
    +      '#value' => $this->t('Submit'),
    +    ];
    +
    +    return $form;
    

    Instead of this, it can

    return parent::buildForm($form, $form_state);
    
  6. +++ b/src/Form/StateLogConfigForm.php
    @@ -0,0 +1,80 @@
    +    $config = $this->configFactory->getEditable('state_log.settings');
    ...
    +    $config->set('log_ignored_state', $ignore_settings_array);
    ...
    +    $config->save();
    

    Can replace with

    $this->config('state_log.settings')
      ->set('log_ignored_state', $ignore_settings_array)
      ->save();
    

    That's the point of getEditableConfigNames, to make the config() method work as expected.

  7. +++ b/src/StateLog.php
    @@ -94,6 +94,24 @@ class StateLog implements StateInterface {
    +   * @param string $state_name
    +   *
    

    Missing param doc

  8. +++ b/src/StateLog.php
    @@ -94,6 +94,24 @@ class StateLog implements StateInterface {
    +   *   State key is ignored.
    

    Something like: TRUE if the state key is ignored, FALSE otherwise.

  9. +++ b/src/StateLog.php
    @@ -94,6 +94,24 @@ class StateLog implements StateInterface {
    +      foreach ($ignored_entities as $ignore) {
    

    This loop is over-indented.

  10. +++ b/src/StateLog.php
    @@ -94,6 +94,24 @@ class StateLog implements StateInterface {
    +        if (fnmatch($ignore, $state_name)) {
    

    Why fnmatch? I've never seen it used in Drupal before, and it's not clear what benefits it provides. But even the PHP docs suggest not to use it...

srdtwc’s picture

StatusFileSize
new4.53 KB

How does this look?

  • tim.plunkett committed 6fecd23 on 8.x-1.x authored by srdtwc
    Issue #3104970 by srdtwc: Provide mechanism to include or exclude state...
tim.plunkett’s picture

Status: Needs review » Fixed
StatusFileSize
new2.79 KB

Thanks! Made a couple other tweaks before commit.
It's good to post an interdiff when you make changes, to help keep track between patches.

srdtwc’s picture

Thanks for the help, Tim!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.