logger example

public function save(array $form, FormStateInterface $form_state) {
    $vocabulary = $this->entity;

    // Prevent leading and trailing spaces in vocabulary names.     $vocabulary->set('name', trim($vocabulary->label()));

    $status = $vocabulary->save();
    $edit_link = $this->entity->toLink($this->t('Edit'), 'edit-form')->toString();
    switch ($status) {
      case SAVED_NEW:
        $this->messenger()->addStatus($this->t('Created new vocabulary %name.', ['%name' => $vocabulary->label()]));
        $this->logger('taxonomy')->notice('Created new vocabulary %name.', ['%name' => $vocabulary->label(), 'link' => $edit_link]);
        $form_state->setRedirectUrl($vocabulary->toUrl('overview-form'));
        break;

      case SAVED_UPDATED:
        $this->messenger()->addStatus($this->t('Updated vocabulary %name.', ['%name' => $vocabulary->label()]));
        $this->logger('taxonomy')->notice('Updated vocabulary %name.', ['%name' => $vocabulary->label(), 'link' => $edit_link]);
        $form_state->setRedirectUrl($vocabulary->toUrl('collection'));
        break;
    }

    $form_state->setValue('vid', $vocabulary->id());
    
// If the source file doesn't exist, return FALSE without creating folders.     $image = $this->getImageFactory()->get($original_uri);
    if (!$image->isValid()) {
      return FALSE;
    }

    // Get the folder for the final location of this style.     $directory = \Drupal::service('file_system')->dirname($derivative_uri);

    // Build the destination folder tree if it doesn't already exist.     if (!\Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) {
      \Drupal::logger('image')->error('Failed to create style directory: %directory', ['%directory' => $directory]);
      return FALSE;
    }

    foreach ($this->getEffects() as $effect) {
      $effect->applyEffect($image);
    }

    if (!$image->save($derivative_uri)) {
      if (file_exists($derivative_uri)) {
        \Drupal::logger('image')->error('Cached image file %destination already exists. There may be an issue with your rewrite configuration.', ['%destination' => $derivative_uri]);
      }
      

  public function save(array $form, FormStateInterface $form_state) {
    $term = $this->entity;

    $result = $term->save();

    $edit_link = $term->toLink($this->t('Edit'), 'edit-form')->toString();
    $view_link = $term->toLink()->toString();
    switch ($result) {
      case SAVED_NEW:
        $this->messenger()->addStatus($this->t('Created new term %term.', ['%term' => $view_link]));
        $this->logger('taxonomy')->notice('Created new term %term.', ['%term' => $term->getName(), 'link' => $edit_link]);
        break;

      case SAVED_UPDATED:
        $this->messenger()->addStatus($this->t('Updated term %term.', ['%term' => $view_link]));
        $this->logger('taxonomy')->notice('Updated term %term.', ['%term' => $term->getName(), 'link' => $edit_link]);
        $form_state->setRedirect('entity.taxonomy_term.canonical', ['taxonomy_term' => $term->id()]);
        break;
    }

    $current_parent_count = count($form_state->getValue('parent'));
    // Root doesn't count if it's the only parent.

  public function save(array $form, FormStateInterface $form_state) {
    $contact_form = $this->entity;
    $status = $contact_form->save();
    $contact_settings = $this->config('contact.settings');

    $edit_link = $this->entity->toLink($this->t('Edit'))->toString();
    $view_link = $contact_form->toLink($contact_form->label(), 'canonical')->toString();
    if ($status == SAVED_UPDATED) {
      $this->messenger()->addStatus($this->t('Contact form %label has been updated.', ['%label' => $view_link]));
      $this->logger('contact')->notice('Contact form %label has been updated.', ['%label' => $contact_form->label(), 'link' => $edit_link]);
    }
    else {
      $this->messenger()->addStatus($this->t('Contact form %label has been added.', ['%label' => $view_link]));
      $this->logger('contact')->notice('Contact form %label has been added.', ['%label' => $contact_form->label(), 'link' => $edit_link]);
    }

    // Update the default form.     if ($form_state->getValue('selected')) {
      $contact_settings
        ->set('default_form', $contact_form->id())
        ->save();
    }
$pass = $account->getPassword();
    $admin = $form_state->getValue('administer_users');
    $notify = !$form_state->isValueEmpty('notify');

    // Save has no return value so this cannot be tested.     // Assume save has gone through correctly.     $account->save();

    $form_state->set('user', $account);
    $form_state->setValue('uid', $account->id());

    $this->logger('user')->info('New user: %name %email.', ['%name' => $form_state->getValue('name'), '%email' => '<' . $form_state->getValue('mail') . '>', 'type' => $account->toLink($this->t('Edit'), 'edit-form')->toString()]);

    // Add plain text password into user account to generate mail tokens.     $account->password = $pass;

    // New administrative account without notification.     if ($admin && !$notify) {
      $this->messenger()->addStatus($this->t('Created a new user account for <a href=":url">%name</a>. No email has been sent.', [':url' => $account->toUrl()->toString(), '%name' => $account->getAccountName()]));
    }
    // No email verification required; log in user immediately.     elseif (!$admin && !\Drupal::config('user.settings')->get('verify_mail') && $account->isActive()) {
      _user_mail_notify('register_no_approval_required', $account);
      
else {
      // Otherwise fall back to the front page.       return Url::fromRoute('<front>');
    }
  }

  /** * Logs a message about the deleted entity. */
  protected function logDeletionMessage() {
    $entity = $this->getEntity();
    $this->logger($entity->getEntityType()->getProvider())->info('The @entity-type %label has been deleted.', [
      '@entity-type' => $entity->getEntityType()->getSingularLabel(),
      '%label' => $entity->label(),
    ]);
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->getEntity()->delete();
    $this->messenger()->addStatus($this->getDeletionMessage());
    
      // implementation is found.       while ($pos = strrpos($hook, '__')) {
        $hook = substr($hook, 0, $pos);
        if ($theme_registry->has($hook)) {
          break;
        }
      }
      if (!$theme_registry->has($hook)) {
        // Only log a message when not trying theme suggestions ($hook being an         // array).         if (!isset($candidate)) {
          \Drupal::logger('theme')->warning('Theme hook %hook not found.', ['%hook' => $hook]);
        }
        // There is no theme implementation for the hook passed. Return FALSE so         // the function calling         // \Drupal\Core\Theme\ThemeManagerInterface::render() can differentiate         // between a hook that exists and renders an empty string, and a hook         // that is not implemented.         return FALSE;
      }
    }

    $info = $theme_registry->get($hook);

    
$source->prepareViewDisplay($media_type$display);
        $display->save();
      }
    }

    $t_args = ['%name' => $media_type->label()];
    if ($status === SAVED_UPDATED) {
      $this->messenger()->addStatus($this->t('The media type %name has been updated.', $t_args));
    }
    elseif ($status === SAVED_NEW) {
      $this->messenger()->addStatus($this->t('The media type %name has been added.', $t_args));
      $this->logger('media')->notice('Added media type %name.', $t_args);
    }

    // Override the "status" base field default value, for this media type.     $fields = $this->entityFieldManager->getFieldDefinitions('media', $media_type->id());
    /** @var \Drupal\media\MediaInterface $media */
    $media = $this->entityTypeManager->getStorage('media')->create(['bundle' => $media_type->id()]);
    $value = (bool) $form_state->getValue(['options', 'status']);
    if ($media->status->value != $value) {
      $fields['status']->getConfig($media_type->id())->setDefaultValue($value)->save();
    }

    
return $this->traitGetDeletionMessage();
  }

  /** * {@inheritdoc} */
  protected function logDeletionMessage() {
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $this->getEntity();

    if (!$entity->isDefaultTranslation()) {
      $this->logger($entity->getEntityType()->getProvider())->info('The @entity-type %label @language translation has been deleted.', [
        '@entity-type' => $entity->getEntityType()->getSingularLabel(),
        '%label'       => $entity->label(),
        '@language'    => $entity->language()->getName(),
      ]);
    }
    else {
      $this->traitLogDeletionMessage();
    }
  }

  /** * {@inheritdoc} */
// Is the output cached?         $cacheName = ! empty($cacheName)
            ? $cacheName
            : str_replace(['\\', '/'], '', $class) . $method . md5(serialize($params));

        if (empty($this->cache) && $output = $this->cache->get($cacheName)) {
            return $output;
        }

        if (method_exists($instance, 'initController')) {
            $instance->initController(Services::request(), Services::response(), Services::logger());
        }

        if (method_exists($instance$method)) {
            throw ViewException::forInvalidCellMethod($class$method);
        }

        $output = $instance instanceof BaseCell
            ? $this->renderCell($instance$method$params)
            : $this->renderSimpleClass($instance$method$params$class);

        // Can we cache it?
'@type' => $node_type->label(),
      '%title' => $this->getEntity()->label(),
    ]);
  }

  /** * {@inheritdoc} */
  protected function logDeletionMessage() {
    /** @var \Drupal\node\NodeInterface $entity */
    $entity = $this->getEntity();
    $this->logger('content')->info('@type: deleted %title.', ['@type' => $entity->getType(), '%title' => $entity->label()]);
  }

}
$this->withRequest(Services::request($this->appConfig, false)->setBody($this->body));

            // Restore the URI service             Services::injectMock('uri', $tempUri);
        }

        if (empty($this->response)) {
            $this->response = Services::response($this->appConfig, false);
        }

        if (empty($this->logger)) {
            $this->logger = Services::logger();
        }
    }

    /** * Loads the specified controller, and generates any needed dependencies. * * @return mixed */
    public function controller(string $name)
    {
        if (class_exists($name)) {
            

      else {
        // Use $form_state->getUserInput() in the error message to guarantee         // that we send exactly what the user typed in. The value from         // $form_state->getValue() may have been modified by validation         // handlers that ran earlier than this one.         $user_input = $form_state->getUserInput();
        $query = isset($user_input['name']) ? ['name' => $user_input['name']] : [];
        $form_state->setErrorByName('name', $this->t('Unrecognized username or password. <a href=":password">Forgot your password?</a>', [':password' => Url::fromRoute('user.pass', []['query' => $query])->toString()]));
        $accounts = $this->userStorage->loadByProperties(['name' => $form_state->getValue('name')]);
        if (!empty($accounts)) {
          $this->logger('user')->notice('Login attempt failed for %user.', ['%user' => $form_state->getValue('name')]);
        }
        else {
          // If the username entered is not a valid user,           // only store the IP address.           $this->logger('user')->notice('Login attempt failed from %ip.', ['%ip' => $this->getRequest()->getClientIp()]);
        }
      }
    }
    elseif ($flood_control_user_identifier = $form_state->get('flood_control_user_identifier')) {
      // Clear past failures for this user so as not to block a user who might       // log in and out more than once in an hour.
$form_state->setRebuild();
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $comment = $this->entity;
    $entity = $comment->getCommentedEntity();
    $field_name = $comment->getFieldName();
    $uri = $entity->toUrl();
    $logger = $this->logger('comment');

    if ($this->currentUser->hasPermission('post comments') && ($this->currentUser->hasPermission('administer comments') || $entity->{$field_name}->status == CommentItemInterface::OPEN)) {
      $comment->save();
      $form_state->setValue('cid', $comment->id());

      // Add a log entry.       $logger->notice('Comment posted: %subject.', [
        '%subject' => $comment->getSubject(),
        'link' => Link::fromTextAndUrl(t('View')$comment->toUrl()->setOption('fragment', 'comment-' . $comment->id()))->toString(),
      ]);

      
try {
      $transaction = $this->database->startTransaction();
      parent::delete($entities);

      // Ignore replica server temporarily.       \Drupal::service('database.replica_kill_switch')->trigger();
    }
    catch (\Exception $e) {
      if (isset($transaction)) {
        $transaction->rollBack();
      }
      Error::logException(\Drupal::logger($this->entityTypeId)$e);
      throw new EntityStorageException($e->getMessage()$e->getCode()$e);
    }
  }

  /** * {@inheritdoc} */
  protected function doDeleteFieldItems($entities) {
    $ids = array_keys($entities);

    $this->database->delete($this->baseTable)
      
Home | Imprint | This part of the site doesn't use cookies.