Skip to content

Instantly share code, notes, and snippets.

View jacksleight's full-sized avatar

Jack Sleight jacksleight

View GitHub Profile
---
sorts:
title: Name
price:asc: Price (Low – High)
price:desc: Price (High – Low)
features:
- Glitter
- Lights
- Sparkles
- Wheels
@jacksleight
jacksleight / rename-package.md
Last active April 27, 2023 07:33
Rename Package

With this method anyone who has the package installed will no longer receive updates and the addon will appear as unlisted in the control panel. The old package will still be installable via composer (GitHub should redirect the old repo URL), however it will output a warning advising the user to switch to the new version.

  1. Disconnect the GitHub repo from Packagist
  2. Rename the GitHub repo
  3. Push an updated composer.json plus anything else that needs renaming
  4. Resubmit the package to Packagist using the new name
  5. Mark the old package as abandoned on Packagist, and use the new name in the form
  6. Update Statamic marketplace with the new GitHub URL and Packagist name
@jacksleight
jacksleight / AppServiceProvider.php
Last active February 28, 2023 14:39
Convert legacy Bard Text Align mark values to Tiptap 2 text align values
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
@jacksleight
jacksleight / Divider.php
Created February 22, 2023 09:40
Statamic Divider Fieldtype
<?php
namespace App\Fieldtypes;
use Statamic\Fields\Fieldtype;
class Divider extends Fieldtype
{
}
@jacksleight
jacksleight / AppServiceProvider.php
Last active December 16, 2022 11:29
Statamic Computed Value Classes
<?php
Statamic::booted(function () {
foreach (app()['files']->files(app_path('Values')) as $file) {
$class = $file->getBasename('.php');
$fqcn = $this->app->getNamespace()."Values\\{$class}";
if (is_subclass_of($fqcn, Values::class)) {
$object = app($fqcn);
$collections = $fqcn::$collections;
$fields = Arr::except(get_class_methods($object), '__construct');
foreach ($collections as $collection) {
@jacksleight
jacksleight / AppServiceProvider.php
Last active October 27, 2022 15:16
Add entry count to taxonomy term listing
<?php
namespace App\Providers;
use App\Taxonomies\LocalizedTerm;
use Illuminate\Support\ServiceProvider;
use Statamic\Taxonomies\LocalizedTerm as StatamicLocalizedTerm;
class AppServiceProvider extends ServiceProvider
{
@jacksleight
jacksleight / statamic_form.php
Last active August 17, 2022 09:01
`statamic_form()` function for Blade
<?php
use Statamic\Tags\Loader;
use Statamic\View\Antlers\Parser;
if (! function_exists('statamic_form')) {
function statamic_form($handle, $params = [])
{
$form = Form::find($handle);
$html = app(Loader::class)->load('form', [
'parser' => app(Parser::class),
@jacksleight
jacksleight / CustomNav.php
Last active January 27, 2022 17:49
Statamic Nav Performance Experiment
<?php
namespace App\Tags;
use Statamic\Tags\Tags;
use Statamic\Contracts\Structures\Structure as StructureContract;
use Statamic\Facades\Site;
use Statamic\Facades\URL;
use Statamic\Structures\TreeBuilder;
use Statamic\Facades\Data;
@jacksleight
jacksleight / README.md
Last active November 20, 2021 20:01
Statamic Replace Asset Action

Statamic Replace Asset Action

Replace an asset with a new file. Also renames the asset to the new name (Statamic will update references).

Known Issues

  1. The asset Browse button doesn't seem to work inside an action modal (statamic/cms#4785). Not a huge issue as you'll probably be uploading a new file anyway, but if it did work you could replace one asset with another, which might be useful.
  2. If you upload a new file and then click Cancel instead of Run the new file will remain at the root of the container.
  3. If you select multiple assets only the first will be replaced.
@jacksleight
jacksleight / BladeTag.php
Last active October 28, 2021 09:38
Statamic Antlers Blade Tag
<?php
namespace App\Tags;
use Statamic\Tags\Tags;
use Symfony\Component\Debug\Exception\FatalThrowableError;
class Blade extends Tags
{
public function index()