Skip to content

Instantly share code, notes, and snippets.

View Anubarak's full-sized avatar

Robin Schambach Anubarak

  • Secondred Newmedia GmbH
View GitHub Profile
$model = new DynamicModel($request->getBodyParams(), [
[
['firstname', 'lastname', 'mail', 'privacy'],
'required',
'message' => Craft::t('site', "Folgendes Feld Fehlt: {attribute}")
]
]);
$model->addRule('minEntryTimeMethod', static function() use ($model){
if (/* kleiner als 3s */) {
$model->addError('title', "Sie haben zu schnell abgesendet");
@Anubarak
Anubarak / ContentMigration.php
Created April 8, 2019 17:45
Custom behavior to add additional attributes to all Elements
<?php
// just a simple migration file to store the information
namespace craft\contentmigrations;
use Craft;
use craft\db\Migration;
/**
<?php
Craft::$app->getView()->hook(
/**
* @param array $context
*/
'cp.entries.edit',
function(array &$context) {
/** @var Section $section */
$section = $context['section'];
Craft.OriginalEntryIndex = Craft.EntryIndex;
Craft.EntryIndex = Craft.OriginalEntryIndex.extend({
afterInit: function(){
this.$statusMenuBtn.data("menubtn").menu.$options[1].click();
this.base.apply(this, arguments);
}
});
delete(Craft._elementIndexClasses["craft\\\elements\\\Entry"]);
Craft.registerElementIndexClass("craft\\\elements\\\Entry", Craft.EntryIndex);
<?php
/**
* ElementCreate Action: this class handles Updating and Creating Craft elements,
*
* API for Craft CMS 3.x
*
* Created with PhpStorm.
*
* @link https://github.com/Anubarak/
* @copyright Copyright (c) 2019 Robin Schambach
@Anubarak
Anubarak / RemoveFields.php
Created March 16, 2019 15:50
Remove fields in the field layout for an entry for certain users
Craft::$app->getView()->hook(
/**
* @param array $context
*/
'cp.entries.edit',
function(array &$context) {
/** @var Section $section */
$section = $context['section'];
/** @var \craft\models\EntryType $entryType */
import axios from 'axios';
// my vuex store
import store from './../store';
axios.defaults.withCredentials = true;
const apiVersion = 'v1';
const apiClient = axios.create({
baseURL: 'https://XYZ/api/' + apiVersion + '/',
headers: {
Accept: 'application/json',
<?php
/**
* How to create an ElementIndex via custom Record for Craft CMS 3.x
*
* @copyright Copyright (c) 2018 anubarak
*/
namespace modules\mymodule\elements\db;
use craft\base\Element;
use craft\db\Query;
<?php
// Element API endpoint
'news.json' => function() {
return [
'elementType' => Entry::class,
'criteria' => [
'section' => 'news'
'join' => [
[
'LEFT JOIN',
$('.youtube-player').youtube();
/**
* Youtube Plugin
*/
(function ($, window, document, undefined) {
var pluginName = 'youtube';
var scriptLoaded = false;
var isTouch = 'ontouchstart' in window,
eStart = isTouch ? 'touchstart' : 'mousedown',