Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

navigation iterator #1941

Closed
wants to merge 2 commits into from
Closed

navigation iterator #1941

wants to merge 2 commits into from

Conversation

staabm
Copy link
Member

@staabm staabm commented Aug 3, 2018

No description provided.

@staabm staabm mentioned this pull request Aug 3, 2018
@staabm
Copy link
Member Author

staabm commented Aug 3, 2018

@skerbis du hast die klasse ja schonmal bentzt, hast du ein paar realisitische beispiele wie du sie verwendest?

/**
* Klasse zum Erstellen von Navigationen, v0.1.
*
* benötigt PHP7!
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ist jetzt 5.5 kompatibel

*
* echo "<li class='rex-navi-depth-". $depth ." rex-nav-". $nth ."nth-child'>";
* echo "<a href='". $ooObj->getUrl() ."'>". $ooObj->getName() ."</a>";
* echo "</li>\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staabm Ich sehe hier konzeptionell noch ein Grundproblem (siehe auch Diskussion unter dem Gist).
Die Unterliste (<ul>) muss mit in das <li>, sonst erhält man keinen validen Code.
Ich sehe aber aktuell keine Möglichkeit, wie man das mit der Klasse erreichen kann, da die Unterliste erst "abgearbeitet" wird, wenn der Oberpunkt fertig durchlaufen ist. Somit bekommt man die Unterliste nicht vor dieses </li> (falls ich nicht was Wesentliches übersehe).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Genau. Sie muss ins <li>, darf aber nicht in den Anker. Und: Es muss auch die Möglichkeit geben, Navigationspunkte ohne Anker zu generieren, bspw. nur mit einem <span> umschlossen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also das markup generiert ja jeder selbst der die klasse benutzt. Es ist nicht so wie bei der navigation-factory wo die klasse das markup vorgibt. D.h. Jeder generiet das markup was er brauch. Das hier sind nur beispiele, man muss die klasse nicht mit dem hier dargestellten markup verwenden.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tja, dann, sind wir wieder am Anfang: praxisnahe und gültige Beispiele...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staabm Ich habe den Eindruck, dass du die Problematik noch nicht ganz siehst, die @tbaddade unter dem gist aufgezeigt hat.
Ich sehe aktuell keine Möglichkeit, mit der Klasse eine sinnvolle/valide ul-li-Struktur über 2 oder mehr Ebenen zu erstellen.
Falls das doch möglich ist, am besten mal beispielhaft skizzieren (und am besten das obige Beispiel damit austauschen, denn da kommt nichts sinnvolles raus, sobald man mehrere Ebenen hat).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich kann das Problem auch bestätigen. Es ist mir nicht aufgefallen, da ich für die Lösungen wo ich es benutze sehr flache Navigationen verwende. Zusätzlich zur depth, benötigt man evtl. noch eine Info haschilds oder Ähnliches damit man direkt reagieren kann. Andernfalls geht's nur, wenn man sich anhand der Daten der gelieferten Structure Elemente selbst noch mal ein Array baut.

@staabm
Copy link
Member Author

staabm commented Aug 7, 2018

folgender navi code liefert für mich eine gültige ul-li liste mit dem iterator:

<?php
$it = rex_navigation_iterator::factory()
   ->ignoreOfflines($ignoreOfflines = true)
;

$nav = '';
$nav .= '<ul class="nav navbar-nav">';
foreach($it as $navItem) {
   // @var rex_article|rex_category $ooObj das aktuelle Element 
   // @var int $depth die aktuelle tiefe/ebene 
   // @var int $nth ein forlaufender Zähler je Ebene 
   // @var int $count Anzahl Elemente auf der aktuellen Ebene 
   list($ooObj, $depth, $nth, $count) = $navItem;

   $nav .= "<li class='rex-navi-depth-". $depth ." rex-nav-". $nth ."nth-child'>";
   $nav .= "<a href='". $ooObj->getUrl() ."'>". $ooObj->getName() ."</a>";

   if ($ooObj->getChildren($ignoreOfflines)) {
       $nav .= '<ul class="dropdown">';
       continue;
   }
    
   if ($ooObj->getParent() && $nth == $count) {
       $nav .= "</li>\n";
       $nav .= '</ul>';
   }

    $nav .= "</li>\n";
}
$nav .= '</ul>';

ist so in der art erstmal keine schönheit, aber ggf. eine erste diskussionsgrundlage.

@skerbis
Copy link
Contributor

skerbis commented Aug 7, 2018

@staabm Leider funktioniert das so nicht, nodes der 1. Ebene verbleiben in der 2.
Auch würde ->depthLimit(2) nicht korrekt funktionieren.

Dein Beispiel ergibt bei mir in einer aktuellen Demo:

<ul class="nav navbar-nav">
<li class='rex-navi-depth-1 rex-nav-1nth-child'><a href='https://demo.klxm.de/'>Start</a></li>
<li class='rex-navi-depth-1 rex-nav-2nth-child'>
   <a href='https://demo.klxm.de/abschnitte-als-module/'>Abschnitte als Module</a>
   <ul class="dropdown">
      <li class='rex-navi-depth-2 rex-nav-1nth-child'>
         <a href='https://demo.klxm.de/abschnitte-als-module/xxxxx/'>xxxxx</a>
         <ul class="dropdown">
            <li class='rex-navi-depth-3 rex-nav-1nth-child'><a href='https://demo.klxm.de/abschnitte-als-module/xxxxx/vcvcvcvcvcvc/'>vcvcvcvcvcvc</a></li>
         </ul>
      </li>
      <li class='rex-navi-depth-1 rex-nav-3nth-child'><a href='https://demo.klxm.de/abschnitte-als-artikel-band-website/'>Abschnitte als Artikel – Band-Website</a></li>
      <li class='rex-navi-depth-1 rex-nav-4nth-child'>
         <a href='https://demo.klxm.de/abschnitte-als-kategorien-reise-website/'>Abschnitte als Kategorien – Reise-Website</a>
         <ul class="dropdown">
            <li class='rex-navi-depth-2 rex-nav-1nth-child'><a href='https://demo.klxm.de/abschnitte-als-kategorien-reise-website/header-modul/'>Header-Modul</a></li>
            <li class='rex-navi-depth-2 rex-nav-2nth-child'><a href='https://demo.klxm.de/abschnitte-als-kategorien-reise-website/bisherige-trips/'>Bisherige Trips</a></li>
            <li class='rex-navi-depth-2 rex-nav-3nth-child'><a href='https://demo.klxm.de/abschnitte-als-kategorien-reise-website/aktuell/'>Aktuell</a></li>
            <li class='rex-navi-depth-2 rex-nav-4nth-child'><a href='https://demo.klxm.de/abschnitte-als-kategorien-reise-website/zahlen/'>Zahlen</a></li>
            <li class='rex-navi-depth-2 rex-nav-5nth-child'><a href='https://demo.klxm.de/abschnitte-als-kategorien-reise-website/polar-weisheiten/'>Polar-Weisheiten</a></li>
         </ul>
      </li>
      <li class='rex-navi-depth-1 rex-nav-5nth-child'>
         <a href='https://demo.klxm.de/multipage-agentur-website/'>Multipage – Agentur-Website</a>
         <ul class="dropdown">
            <li class='rex-navi-depth-2 rex-nav-1nth-child'><a href='https://demo.klxm.de/multipage-agentur-website/agentur/'>Agentur</a></li>
            <li class='rex-navi-depth-2 rex-nav-2nth-child'><a href='https://demo.klxm.de/multipage-agentur-website/leistungen/'>Leistungen</a></li>
            <li class='rex-navi-depth-2 rex-nav-3nth-child'><a href='https://demo.klxm.de/multipage-agentur-website/referenzen/'>Referenzen</a></li>
         </ul>
      </li>
   </ul>

@skerbis
Copy link
Contributor

skerbis commented Oct 6, 2018

Folgt auf ein Element 3 Ebene ein Element 1 Ebene, landet es nicht in der 1. Ebene sondern in der 2.

@alxndr-w
Copy link
Contributor

alxndr-w commented Oct 6, 2018

Angesichts der offensichtlichen Praxisprobleme von diesem Ansatz möchte ich gerne an eine der ursprünglichen Alternativen für Navigationen erinnern, die sich am SEO42 Add-On orientieren.

In den meisten Fällen würde es allerdings schlichtweg genügen, per callback Einfluss auf den Ankerinhalt oder das ul-Element einer Ebene nehmen zu können, ohne sich Tricks wie regex-Ersetzungen behelfen zu müssen.

Das lässt sich mit Sicherheit in die bestehende rex_navigation ohne BC implementieren.

@skerbis
Copy link
Contributor

skerbis commented Oct 6, 2018

Folgender Code erzeugt bei mir eine korrekte UL-Liste. Kann man sicher noch optimieren und schöner machen. @staabm

<?php
$it = rex_navigation_iterator::factory()->ignoreOfflines($ignoreOfflines = true);

$nav = '';

$predepth = 0;
foreach ($it as $navItem)
{
    // @var rex_article|rex_category $ooObj das aktuelle Element
    // @var int $depth die aktuelle tiefe/ebene
    // @var int $nth ein forlaufender Zähler je Ebene
    // @var int $count Anzahl Elemente auf der aktuellen Ebene
    //  dump($navItem);
    list($ooObj, $depth, $nth, $count) = $navItem;

    $nav .= $navpre;

    if ($predepth == $depth)
    {
        $nav .= "</li>\n";
    }
    if ($predepth < $depth && $predepth != 0)
    {
        $nav .= "\n<ul>\n";
    }
    while ($predepth > $depth)
    {
        $nav .= "</ul>\n</li>\n";
        $predepth--;
    }

    $navpre = "<li><a href='" . $ooObj->getUrl() . "'>" . $ooObj->getName() . "</a>";

    $predepth = $depth;
}
// Letztes Element
$nav .= "<li><a href='" . $ooObj->getUrl() . "'>" . $ooObj->getName() . "</a>";

if ($predepth == $depth)
{
    $nav .= "</li>\n";
}
if ($predepth < $depth && $predepth != 0)
{
    $nav .= "\n<ul>\n";
}
while ($predepth > $depth)
{
    $nav .= "</ul>\n</li>\n";
    $predepth--;
}

echo "<ul>" . $nav . "</ul>";

@staabm staabm closed this Dec 10, 2018
@staabm staabm deleted the nav-iter branch December 10, 2018 21:31
@staabm
Copy link
Member Author

staabm commented Dec 10, 2018

Das angepeilte ziel kann man dem Ansatz leider nicht erreicht werden

@skerbis
Copy link
Contributor

skerbis commented Dec 10, 2018

:-(

@alxndr-w
Copy link
Contributor

Können wir dann wieder darüber sprechen, die Navigation Factory zu erweitern, um wenigstens den Anker-Inhalt im Callback verändern zu können?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants