Coder Social home page Coder Social logo

crumb's Introduction

Crumb

Latest Stable Version Build Status Total Downloads

A simple breadcrumb package for Sage 10.

Requirements

Installation

Install via Composer:

$ composer require log1x/crumb

Usage

Publish the breadcrumb configuration file using Acorn:

$ wp acorn vendor:publish --provider="Log1x\Crumb\CrumbServiceProvider"

Example

# app/View/Components/Breadcrumb.php

<?php

namespace App\View\Components;

use Roots\Acorn\View\Component;
use Log1x\Crumb\Facades\Crumb;

class Breadcrumb extends Component
{
    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * The breadcrumb items.
     *
     * @return string
     */
    public function items()
    {
        return Crumb::build()->toArray();
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\View\View|string
     */
    public function render()
    {
        return $this->view('components.breadcrumb');
    }
}
# views/components/breadcrumb.blade.php

@if (! empty($items))
  <nav
    aria-label="Breadcrumb"
    class="flex items-center py-2 -mx-2 leading-none"
    vocab="https://schema.org/"
    typeof="BreadcrumbList"
  >
    @foreach ($items as $item)
      @if (empty($item['url']))
        <span class="p-2 font-medium cursor-default">
          {{ $item['label'] }}
        </span>
      @else
        <span class="p-2" property="itemListElement" typeof="ListItem">
          <a
            property="item"
            typeof="WebPage"
            title="Go to {!! $item['label'] !!}."
            href="{{ $item['url'] }}"
            class="hover:text-indigo-500"
          >
            <span property="name">
              @if ($loop->first)
                <svg
                  class="flex-shrink-0 w-5 h-5"
                  xmlns="http://www.w3.org/2000/svg"
                  viewBox="0 0 20 20"
                  fill="currentColor"
                  aria-hidden="true"
                >
                  <path d="M10.707 2.293a1 1 0 00-1.414 0l-7 7a1 1 0 001.414 1.414L4 10.414V17a1 1 0 001 1h2a1 1 0 001-1v-2a1 1 0 011-1h2a1 1 0 011 1v2a1 1 0 001 1h2a1 1 0 001-1v-6.586l.293.293a1 1 0 001.414-1.414l-7-7z" />
                </svg>

                <span class="sr-only">{!! $item['label'] !!}</span>
              @else
                {!! $item['label'] !!}
              @endif
            </span>
          </a>

          <meta property="position" content="{{ $loop->iteration }}">
        </span>

        @if (!$loop->last)
          <svg class="flex-shrink-0 w-5 h-5 text-indigo-300" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
            <path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd" />
          </svg>
        @endif
      @endif
    @endforeach
  </nav>
@endif

Bug Reports

If you discover a bug in Crumb, please open an issue.

Contributing

Contributing whether it be through PRs, reporting an issue, or suggesting an idea is encouraged and appreciated.

License

Crumb is provided under the MIT License.

crumb's People

Contributors

gmutschler avatar log1x avatar mateuszswol avatar mike-sheppard avatar ouun avatar suetin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

crumb's Issues

Installation in sage / bedrock ?

Apologies in advance for any misunderstandings. I'm trying to install this to my Sage10 app, but can't seem to get it to work.

Installing it to sage gives me the option to release the config file, but gives a "base_path" error.

Call to undefined function Illuminate\Foundation\Console\base_path()

Installing it to bedrock lets phpstorm recognize the class "Log1x\Crumb\Facades\Crumb;" in "View/Components/Breadcrumb.php", but gives an error when compiling;

Class 'Crumb' not found

Any help would be appriciated!

Issue with looping over items

Hi, I was trying to use this package in one my projects and I noticed that in breadcrumb.blade.php component you are accessing the items() method as a variable. If I die and dumb the $item variable it returns an object instance instead of an array.

This works when you loop over the object for reasons unknown, however the $loop variable inside the loop does not have proper values for 'remaining', 'count', 'last' and so on.

I was able to solve this by using $items() instead of $item.

I am pretty intermediate in my knowledge relating to Laravel and Blade. I am just looking to see if I am missing something here.

Thanks,
Aarish

PHP Deprecated: Creation of dynamic property

I'm getting this warning using Crumb v1.1.3 & PHP 8.2.10:

PHP Deprecated: Creation of dynamic property Log1x\Crumb\Crumb::$config is deprecated in [...]vendor/log1x/crumb/src/Crumb.php on line 25

btw, thanks for your work on WP, ACF & Sage, just sent a small amount to support that.

Taxonomy terms in breadcrumb

Hi, I'm using this package for the first time. I successfully managed to create a bredcrumb, but I need to show also associated taxonomy term between page and post title.

app/View/Components/Breadcrumb.php

<?php

namespace App\View\Components;

use Illuminate\View\Component;
use Log1x\Crumb\Facades\Crumb;

class Breadcrumb extends Component
{
    /**
     * Create a new component instance.
     */
    public function __construct()
    {
        //
    }

    public function items()
    {
        return Crumb::build()->toArray();
    }

    /**
     * Get the view / contents that represent the component.
     */
    public function render()
    {
        return $this->view('components.breadcrumb');
    }
}

and this is my blade

resources/views/components/breadcrumb.blade.php


@if (!empty($items))
    <nav class="n7-breadcrumb " aria-label="Breadcrumb">
        <ol class="flex flex-wrap">
            @foreach ($items as $item)
                @if (empty($item['url']))
                    <li>
                        <a class="inline-flex items-center p-1 text-xs n7-content-03 font-bold hover:underline"
                            href="#" aria-current="page">
                            {!! $item['label'] !!}
                        </a>
                    </li>
                @else
                    <li>
                        <a class="inline-flex items-center p-1 text-xs n7-content-03 hover:underline"
                            href="{{ $item['url'] }}">
                            @if ($loop->first)
                                {!! __('Home', 'offhealth') !!}
                            @else
                                {!! $item['label'] !!}
                            @endif
                    </li>
                    @if (!$loop->last)
                        <svg class="inline-block align-middle fill-current w-4 h-4 text-neutral-400 ml-2"
                            aria-hidden="true" focusable="false" role="img">
                            <use xlink:href="@asset('images/icons.svg')#mini--chevron-right" />
                        </svg>
                    @endif
                    </a>
                @endif
            @endforeach
        </ol>
    </nav>
@endif

The result is Home -> Custom Post Type -> Post:
Screenshot 2024-04-16 alle 12 57 00

What I expect is Home -> Custom Post Type -> Taxonomy Term (if post have one) -> Post.

How to deal with this?

Url is set to 1

Hi,

On blog pages, url in the breadcrumb for the last item is set to 1.

Here is a dump of my items :

array:2 [▼
  0 => array:2 [▼
    "label" => "Accueil"
    "url" => "http://dev.cormary.com:8888"
  ]
  1 => array:2 [▼
    "label" => "Acide hyaluronique"
    "url" => "1"
  ]
]

I think, it come from that :

if (is_category()) {
            return $this->add(
                single_cat_title('', false),
                true
            );
        }

Why is there a true as second parameter? I have set the method to :

protected function add(string $key, ?string $value = null, bool $blog = false)

I think $value is casted to a string when pushing the url in

 $this->breadcrumb->push(
            [
                'label' => $key,
                'url'   => $value,
            ]
        );

Undefined variable: items

Hi,

I am getting an error in my code, it doesn't seem to be passing the variable $items, so when using var_dump the error shows.

I have acorn installed.

Also to note, it seems it isn't registering the Breadcrumb component, as when I echo any text it won't show either.

This is my component file and linking to the correct template file.

<?php

namespace App\View\Components;

use Roots\Acorn\View\Component;
use Log1x\Crumb\Facades\Crumb;

class Breadcrumb extends Component
{
    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * The breadcrumb items.
     *
     * @return string
     */
    public function items()
    {
        return Crumb::build()->toArray();
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\View\View|string
     */
    public function render()
    {
        return $this->view('components.breadcrumb');
    }
}

No parent for categories

Hi, I love the simplicity of this plugin! Nice work!

I just tried it out for the first time, and it seems to be working fine except I don't get the ancestors for categories or custom post types and taxnonomies. Is there a setting for it, or is it not include by choice?

Crumbs not working on tax

I want to use Crumb on taxonomy page and I encountered error: Attempt to read property "term_id" on bool.

I found an issue in

get_term_by('title', $term, get_query_var('taxonomy'))->term_id
.

We should use name instead of title in get_term_by().

Crumbs not outputting at all

I have added this packed to my sage 10 site and I can't get the breadcrumbs to display.

Is this outdated? there are also deprecation error for use Roots\Acorn\ServiceProvider;
if I use use Roots\Acorn\Sage\SageServiceProvider it goes away.

Also return Crumb::build()->toArray(); throws an Undefined Type. but this goes away if I use SageServiceProvider.

Does this need an update or is there a new/better way to get breadcrumbs for sage that I don't know about?

Add crumb type to entries

Hi @Log1x,

I hope you are doing great.
Just recognized that for posts Crumb adds all selected categories to the array. Having a couple of categories makes it quite chaotic.

I am using The SEO Framework which adds a "Primary Category" feature that I would like to use. For that I would like to hook into the array and just remove all category crumbs except the primary one.

However currently it is not possible to differate between the crumb types (page, front-page, taxomomy, ...) and therefor I am thinking about a PR to add the "type" to each crumb array. That would allow us to better adjust the crumbs before passed to the view.

Wondering what you think about it.

Thanks and kind regards,

Philipp

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.