Skip to content

Instantly share code, notes, and snippets.

View pepeloper's full-sized avatar
🎯

Pepe pepeloper

🎯
View GitHub Profile
@pepeloper
pepeloper / git
Created July 18, 2018 07:39
Delete merged branchs
git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
@pepeloper
pepeloper / Timestamp.php
Created May 8, 2018 10:25
Laravel validation rule for request
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use Carbon\Carbon;
class Timestamp implements Rule
{
/**
@pepeloper
pepeloper / ProfileJsonResponse.php
Created December 15, 2017 08:56
Middleware to use Laravel debugbar on JSON responses.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\JsonResponse;
class ProfileJsonResponse
{
/**
@pepeloper
pepeloper / CronSchedule.php
Created October 2, 2017 14:24 — forked from m4tthumphrey/CronSchedule.php
CronSchedule.php - Allows one to parse a cron expression into human readable text.
<?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 March 20, 2017 12:58
Trim string in Drupal way

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 March 27, 2017 10:41
Custom field formatter settings

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