<% class_name = class_name.presence || object.class.name.demodulize.underscore.humanize.downcase %>
<% input_class_name = parent_class.presence || object.class.to_s.underscore %>
<% verb = verb || "save" %>

<% if object.errors.present? %>
  <div class="gem-c-error-summary govuk-error-summary" data-module="govuk-error-summary" aria-labelledby="error-summary-title" role="alert" id="error-summary" data-govuk-error-summary-module-started="true">
    <h2 class="govuk-error-summary__title" id="error-summary-title">
      To <%= verb %> the <%= class_name %> please fix the following issues:
    </h2>

    <div class="govuk-error-summary__body">
      <ul class="govuk-list govuk-error-summary__list">
        <% object.errors.map do |error| %>
          <% analytics_action = "#{class_name}-error" %>
          <% error_message = error.full_message %>

          <%= tag.li(
            tag.a(
              error_message,
              href: "##{input_class_name}_#{error.attribute.to_s.gsub(".", "_")}",
              class: "govuk-link"
            ),
            data: track_analytics_data("form-error", analytics_action, error_message),
            class: "gem-c-error-summary__list-item"
          ) %>
        <% end %>
      </ul>
    </div>
  </div>
<% end %>

<% class_name = class_name.presence || object.class.name.demodulize.underscore.humanize.downcase %>
<% input_class_name = parent_class.presence || object.class.to_s.underscore %>
<% verb = verb || "save" %>

<% if object.errors.present? %>
  <%= render "govuk_publishing_components/components/error_summary", {
    title: "To #{verb} the #{class_name} please fix the following issues:",
    items: object.errors.map do |error|
      analytics_action = "#{class_name}-error"
      error_message = error.full_message

      {
        text: error_message,
        href: "##{input_class_name}_#{error.attribute.to_s.gsub(".", "_")}",
        data_attributes: track_analytics_data("form-error", analytics_action, error_message)
      }
    end
  } %>
<% end %>

Replace custom error summary with component
Replace custom error summary with component

This will fix issues where clicking on the links would take users to the input rather than label.

This also simplifies the code so we do not need to maintain more custom code.
