{% import 'macros/form.html' as form %}

{% set read_endpoint = '.read' if h.ckan_version() > '2.9' else '_read' %}

{%- if entity_type == 'dataset' %}
    {%- set controller = 'package' -%}
{%- elif entity_type == 'organization' %}
    {%- set controller = 'organization' -%}
{%- elif entity_type == 'group' -%}
    {%- set controller = 'group' -%}
{%- endif -%}

{%- set module_placeholder = '<' + object_type + '>' -%}

{%- set prefix = h.url_for(object_type + read_endpoint, id='') -%}
{%- set domain = h.url_for(object_type + read_endpoint, id='', qualified=true) -%}
{%- set domain = domain|replace("http://", "")|replace("https://", "") -%}
{%- set attrs = {
    'data-module': 'slug-preview-slug',
    'data-module-prefix': domain,
    'data-module-placeholder': module_placeholder } -%}

{{ form.prepend(
    field.field_name,
    id='field-' + field.field_name,
    label=h.scheming_language_text(field.label),
    prepend=prefix,
    placeholder=h.scheming_language_text(field.form_placeholder),
    value=data[field.field_name],
    error=errors[field.field_name],
    attrs=attrs,
    is_required=h.scheming_field_required(field)
    ) }}

{%- snippet 'scheming/form_snippets/help_text.html', field=field -%}
