Skip to content

Instantly share code, notes, and snippets.

Avatar
👥
Remate

Pepe pepeloper

👥
Remate
View GitHub Profile
@pepeloper
pepeloper / git
Created Jul 18, 2018
Delete merged branchs
View git
git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
@pepeloper
pepeloper / Timestamp.php
Created May 8, 2018
Laravel validation rule for request
View Timestamp.php
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use Carbon\Carbon;
class Timestamp implements Rule
{
/**
@pepeloper
pepeloper / ProfileJsonResponse.php
Created Dec 15, 2017
Middleware to use Laravel debugbar on JSON responses.
View ProfileJsonResponse.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\JsonResponse;
class ProfileJsonResponse
{
/**
@pepeloper
pepeloper / CronSchedule.php
Created Oct 2, 2017 — forked from m4tthumphrey/CronSchedule.php
CronSchedule.php - Allows one to parse a cron expression into human readable text.
View CronSchedule.php
<?php
/*
* Plugin: StreamlineFoundation
*
* Class: Schedule
*
* Description: Provides scheduling mechanics including creating a schedule, testing if a specific moment is part of the schedule, moving back
* and forth between scheduled moments in time and translating the created schedule back to a human readable form.
*
* Usage: ::fromCronString() creates a new Schedule class and requires a string in the cron ('* * * * *', $language) format.
@pepeloper
pepeloper / drupal_trim_string.md
Created Mar 20, 2017
Trim string in Drupal way
View drupal_trim_string.md

Drupal Snippet

In this snippet we will know how to trim any string in Drupal way using the truncate_utf8 function

Code

truncate_utf8($string, $max_length, $wordsafe = FALSE, $add_ellipsis = FALSE, $min_wordsafe_length = 1)

So for example we can do something like this:

@pepeloper
pepeloper / field_formatter_settings.md
Last active Mar 27, 2017
Custom field formatter settings
View field_formatter_settings.md

Drupal Snippet

This snippet is a follow up from this one: Crear formato personalizado para un campo de tipo fecha

In order to implement a settings form to our custom field formatter we only need to use the 'settings' parameter in the field formatter declaration (in hook_field_formatter_info()) and a few hooks.

Through the hook_field_formatter_settings_summary() we can implement a summary showing the configuration used.

hook_field_formatter_settings_summary

You can’t perform that action at this time.