Skip to content

Instantly share code, notes, and snippets.

@ChristopherDosin
Created January 5, 2020 13:15
Show Gist options
  • Save ChristopherDosin/cccac7417b06ef781388afe519274ad7 to your computer and use it in GitHub Desktop.
Save ChristopherDosin/cccac7417b06ef781388afe519274ad7 to your computer and use it in GitHub Desktop.
submitarticle
{# Get the requested entry slug from the URL #}
{% set requestedSlug = craft.app.request.segments|last %}
{# Fetch the entry with that slug #}
{% set entry = craft.entries()
.slug(requestedSlug|literal)
.anyStatus()
.one() %}
{% if entry|length %}
{% set submission = craft.workflow.submissions()
.ownerId(entry.id)
.status('pending')
.first() %}
{% else %}
{% set submission = null %}
{% endif %}
{% block content %}
{% if submission is defined and submission is not null %}
{% set disabled = 'disabled' %}
{% else %}
{% set disabled = '' %}
{% endif %}
<section class="section-hero-only-text with-button write-article background--grey">
<div class="grid-container">
<div class="grid-x">
{% if submission is defined and submission is not null %}
<div class="cell small-12 text-row mb-2">
<h1 class="margin-bottom-2">Artikel in Überprüfung</h1>
<a class="button primary" style="max-width: 420px;" href="{{ url('mitgliederbereich/meine-expertentipps/uebersicht') }}">Übersicht / noch einen Expertentipp verfassen</a>
</div>
{% else %}
<h1 class="margin-bottom-2">
{% if entry is null %}
Expertentipp einreichen
{% else %}
Expertentipp bearbeiten
{% endif %}
</h1>
{% endif %}
</div>
<div class="cell small-12">
<div class="card">
<div class="card-section">
{% macro errorList(errors) %}
{% if errors %}
<ul class="errors">
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
<form method="post" accept-charset="UTF-8">
{{ csrfInput() }}
{{ actionInput('entries/save-entry') }}
<input type="hidden" name="typeId" value="6">
{{ hiddenInput('sectionId', '5') }}
{% if entry|length %}
{{ hiddenInput('entryId', entry.id) }}
{% endif %}
{{ redirectInput('mitgliederbereich/meine-expertentipps/{slug}') }}
<div class="">
<h5 class="margin-bottom-1">Ihr Expertentipp</h5>
</div>
<div class="margin-bottom-1" style="margin-bottom: 20px;">
<input {{ disabled }} type="text" maxlength="160" name="title" placeholder="Titel des Artikels ..." {%- if entry != null %} value="{{ entry.title }}" {% endif -%} required>
{% if entry != null %}
{{ _self.errorList(entry.getErrors('title')) }}
{% endif %}
</div>
<div class="margin-bottom-1">
<label for="category">
Hauptthema
{% set categories = craft.categories().group('versicherungs_article').level('= 1').all() %}
{% set currentCategoryId = '' %}
{% if entry.category is defined %}
{% for cat in entry.category %}
{% set currentCategoryId = cat.id %}
{% endfor %}
{% endif %}
<input {{ disabled }} type="hidden" name="fields[category]" value="">
<select {{ disabled }} id="category" name="fields[category][]" required>
{% for category in categories %}
<option value="{{ category.id }}" {{ category.id == currentCategoryId ? 'selected' }}>{{ category.title }}</option>
{% endfor %}
</select>
</label>
</div>
<div>
{# You need to include the 'type' input to identify the matrix block type you are submitting. #}
<input type="hidden" name="fields[content_builder][new1][type]" value="copy">
{% if submission is defined and submission is not null %}
<div class="redactor-box redactor-styles-on" style="background-color: #e6e6e6; cursor: not-allowed;">
<div class="redactor-styles">
{% for block in entry.content_builder %}
{{ block.copy }}
{% endfor %}
</div>
</div>
{% else %}
<textarea id="content" name="fields[content_builder][new1][fields][copy]" placeholder="...">
{%- if entry != null %}
{% for block in entry.content_builder %}
{{ block.copy }}
{% endfor %}
{% endif -%}
</textarea>
{% endif %}
</div>
<div>
<h5 class="margin-top-2 margin-bottom-1">Suchmaschinenoptimierung</h5>
<div class="margin-bottom-1" style="margin-bottom: 20px;">
<label>Meta-Titel<br>
<small>Der Meta Titel wird bei Suchmaschinen in den Suchergebnissen angezeigt und sollte 60 Zeichen nicht übersteigen.</small>
</label>
<input {{ disabled }} type="text" maxlength="160" name="fields[metaTitle]" placeholder="Browser Titel ..." {%- if entry != null %} value="{{ entry.metaTitle }}" {% endif -%} required>
{% if entry != null %}
{{ _self.errorList(entry.getErrors('metaTitle')) }}
{% endif %}
</div>
<div class="margin-bottom-1" style="margin-bottom: 20px;">
<label>Meta-Beschreibung<br>
<small>Die Länge der Beschreibung sollte 160 Zeichen nicht übersteigen.</small>
<small>
<strong>
<span id="rchars">160</span>
</strong>
Zeichen übrig.</small>
</label>
<input {{ disabled }} type="text" maxlength="160" name="fields[metaDescription]" placeholder="Kurze Beschreibung des Artikels ..." {%- if entry != null %} value="{{ entry.metaDescription }}" {% endif -%} required>
{% if entry != null %}
{{ _self.errorList(entry.getErrors('fields[metaDescription]')) }}
{% endif %}
</div>
</div>
{% if entry|length %}
<div>
<h5 class="margin-top-2 margin-bottom-1">Artikel einreichen</h5>
{# Add our 'hook' for the entry to be submitted for review #}
<label class="dc privacy-check">
<input {{ disabled }} type="checkbox" name="workflow-action" value="save-submission" {% if submission is defined and submission is not null %} checked {% endif %}>
{% if submission is defined and submission is not null %}
<p>Der Artikel wurde bereits eingereicht</p>
{% else %}
<p>Artikel einreichen.</p>
{% endif %}
<p>
<strong>Bitte beachten Sie, dass sobald Sie den Artikel eingereicht haben, dieser nicht mehr editierbar ist.</strong>
</p>
<span class="checkmark"></span>
</label>
</div>
{% endif %}
{% if not entry and membersArea.expertentippInfotext|length %}
<div class="margin-bottom-1">
<div class="alert-box-wrapper flex-child-grow">
<div class="grid-x alert-box">
<div class="cell shrink">
<svg xmlns="http://www.w3.org/2000/svg" width="21" height="21" viewbox="0 0 21 21">
<path fill="#002373" fill-rule="evenodd" d="M9.465 12.708V9.807h-.444a.785.785 0 1 1 0-1.57h.615c.772 0 1.399.626 1.399 1.4v3.07c0 .245.199.444.444.444h.614a.785.785 0 0 1 0 1.57h-.614a2.014 2.014 0 0 1-2.014-2.013zm-.614-6.451a1.092 1.092 0 1 1 2.184 0 1.092 1.092 0 0 1-2.184 0zM10.25.25c5.523 0 10 4.477 10 10s-4.477 10-10 10-10-4.477-10-10 4.477-10 10-10zm0 1.57a8.43 8.43 0 1 0 0 16.86 8.43 8.43 0 0 0 0-16.86z"></path>
</svg>
</div>
<div class="cell auto">
{{ membersArea.expertentippInfotext }}
</div>
</div>
</div>
</div>
{% endif %}
<div class="margin-top-2">
<input class="button" style="max-width: 250px;" type="submit" value="Artikel speichern" {{ disabled }}>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment