astridx / meinblog

4 stars 5 forks source link

en/der-weg-zu-joomla4-erweiterungen/ #18

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Joomla 4.x Tutorial - Extension Development - The Way to Joomla 4 Extensions | Astrid Günther

Component Preface The first view in the backend Joomla update and change log setup The First View in the Frontend A Menu Item The M in MVC…

https://blog.astrid-guenther.de/en/der-weg-zu-joomla4-erweiterungen/

MrTobyDog commented 2 years ago

Been using your code as an example to convert my existing J3 component to J4. I have found a slight problem in src\View\Foo\HtmlView.php - the system complains that there are not enough parameters to onContentPrepare - looking at other components I added a 3rd parameter of &$item->params which seems to work. But apart from that everything is great so far and you have saved me a lot of work!

astridx commented 2 years ago

@MrTobyDog Thank you very much for your advice.

You are right. The onContentPrepare() method should have three parameters. I have just corrected this in the sample code (https://github.com/astridx/boilerplate/commit/5a6e4546ad8bc1e6e5772154df86b825cc3339f8) and will correct the text in the next few days.

However, if you followed my example exactly, there should have been no error. Can you tell me exactly where the error was displayed or what the text was exactly?

MrTobyDog commented 2 years ago

Thanks Astrid, I cannot recall exactly what I did and clearly I had also copied something else incorrectly as I had other issues so I am starting again. If I get the problem again I will get the details for you. Dave

On Sat, 2 Oct 2021 at 07:38, Astrid @.***> wrote:

@MrTobyDog https://github.com/MrTobyDog Thank you very much for your advice.

You are right. The onContentPrepare() method should have three parameters. I have just corrected this in the sample code ( @.*** https://github.com/astridx/boilerplate/commit/5a6e4546ad8bc1e6e5772154df86b825cc3339f8) and will correct the text in the next few days.

However, if you followed my example exactly, there should have been no error. Can you tell me exactly where the error was displayed or what the text was exactly?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/astridx/meinblog/issues/18#issuecomment-932591668, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUEV54PVYTUNLDV6GJ2XILUEYS5HANCNFSM5FBE2LAA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

MrTobyDog commented 2 years ago

OK - to avoid any errors in copying I downloaded the complete ZIP of com_foos and re-installed. I was at stage 25 (Layout) in your plan as I had been going through testing all parts. When I went to ?option=com_foos&id=2&view=foo to test I initially got an error in components\com_foos\src\Model\FooModel.php because the die statement before the first use had no ; I fixed that and refreshed the screen and got a stack trace with Too few arguments to function RegularLabs\Library\SystemPlugin::onContentPrepare(), 2 passed in D:\OneDrive\Documents\WebSites\Joomla 4\libraries\src\Plugin\CMSPlugin.php on line 285 and at least 3 expected Thanks Dave

On Sat, 2 Oct 2021 at 08:14, Dave Torr @.***> wrote:

Thanks Astrid, I cannot recall exactly what I did and clearly I had also copied something else incorrectly as I had other issues so I am starting again. If I get the problem again I will get the details for you. Dave

On Sat, 2 Oct 2021 at 07:38, Astrid @.***> wrote:

@MrTobyDog https://github.com/MrTobyDog Thank you very much for your advice.

You are right. The onContentPrepare() method should have three parameters. I have just corrected this in the sample code ( @.*** https://github.com/astridx/boilerplate/commit/5a6e4546ad8bc1e6e5772154df86b825cc3339f8) and will correct the text in the next few days.

However, if you followed my example exactly, there should have been no error. Can you tell me exactly where the error was displayed or what the text was exactly?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/astridx/meinblog/issues/18#issuecomment-932591668, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUEV54PVYTUNLDV6GJ2XILUEYS5HANCNFSM5FBE2LAA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

astridx commented 2 years ago

Thank you very much for the clarification. I have already corrected the example code. I have just inserted the text in the tutorial post (https://blog.astrid-guenther.de/en/joomla-custom-fields-im-frontend-integrieren). I hope that is understandable:

Are you wondering why we set &$item->params as parameters for the event methods onContentPrepare, onContentAfterTitle, onContentBeforeDisplay and onContentAfterDisplay, although we have not yet explicitly implemented &$item->params in the Foo extension? Implicitly, the populateState method of the file /components/com_foos/src/Model/FooModel.php ensures that &$item->params is available. For our example, we do not need this third parameter so far. However, it is possible that errors may occur in combination with other extensions if this parameter is not set. Therefore, we set the three mandatory parameters ['com_foos.foo', &$item, &$item->params] for all event methods.

MrTobyDog commented 2 years ago

Thanks - that is clear!

On Tue, 5 Oct 2021 at 09:39, Astrid @.***> wrote:

Thank you very much for the clarification. I have already corrected the example code. I have just inserted the text in the tutorial post ( https://blog.astrid-guenther.de/en/joomla-custom-fields-im-frontend-integrieren). I hope that is understandable:

Are you wondering why we set &$item->params as parameters for the event methods onContentPrepare, onContentAfterTitle, onContentBeforeDisplay and onContentAfterDisplay, although we have not yet explicitly implemented &$item->params in the Foo extension? Implicitly, the populateState method of the file /components/com_foos/src/Model/FooModel.php ensures that &$item->params is available. For our example, we do not need this third parameter so far. However, it is possible that errors may occur in combination with other extensions if this parameter is not set. Therefore, we set the three mandatory parameters ['com_foos.foo', &$item, &$item->params] for all event methods.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/astridx/meinblog/issues/18#issuecomment-933909153, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUEV54OUEXSHVS7LO3TVGTUFIULLANCNFSM5FBE2LAA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Phanti09 commented 2 years ago

Hallo, ich versuche anhand deines Tutorials und deines Buches das facile Template für meine Webseite zu nutzen. Wenn ich meine Beispieldaten benutze, wird nur die linke Hälfte der Bildschirms für die Beiträge genutzt. Das TXT Template unterstützt die Darstellung ohne Sidebar (was ich gern erreichen möchte), mit Sidebar links oder Sidebar rechts. Ich habe dazu im Backend (templateDetails.xml) entsprechende Schalter eingefügt:

/> />

Jetzt hapert es bei meinem Verständnis dafür, wie diese Optionen sich ins Layout übertragen kann. Für etwas Nachhilfe wäre ich dankbar. LG Stefan

astridx commented 2 years ago

@Phanti09 Ich werde beim im Kapitle zu den Parametern dies ergänzen:

Tipp: Du möchtest optional im Template festlegen, welche Modulposition verwendet wird. Ist es für dich zum Beispiel wichtig, dass eine Sidebar komplett deaktiviert werden kann? Dann lege den Parameter showSidebarLeft an und erweitere die Zeile <?php if ($this->countModules('sidebar-left', true)) : ?>. Am Ende sollte daraus <?php if ($this->countModules('sidebar-left', true) && $this->params->get('showSidebarLeft')) : ?> werden.

Beantwortet das deine Frage?

Phanti09 commented 2 years ago

Hallo astridx, ja und nein - aber danke für den Tipp. Ich hab zwar Erfahrung im programmieren, aber bei HTML, CSS, Bootstrap und PHP sind meine Kenntnisse sehr oberflächlich. Daher brauchte es ein paar Abende, um mein Problem zu lösen. Ich habe in der templateDetails.xml folgende Änderung gemacht:

/> /> />

Dadurch gibt im Backend den Reiter Sidebar, der drei Schalter hat, keine Sidebar, Sidebar link und Sidebar rechts. Die entsprechenden Texte hab ich in der Datei en-GB.tpl_facile.ini ergänzt. TPL_FACILE_SIDEBAR_LABEL="No Sidebar" TPL_FACILE_SIDEBAR_LEFT_LABEL="Sidebar on the left" TPL_FACILE_SIDEBAR_RIGHT_LABEL="Sidebar on the right"

Dann hab ich die index.php nach dem Muster des TXT Templates angepasst. Die Änderung beginnt nach dem endif für die Banner-Abfrage

    <?php if ($this->params->get('showSidebar')) : ?>
        <section id="main">
                <div class="container">
                    <div class="row">
                        <div class="col-12">
                            <div class="content">

                                <!-- Content -->

                            <?php if ($this->countModules('search', true)) : ?>
                            <section id="search">
                                <jdoc:include type="modules" name="breadcrumbs" style="none" />
                            </section>
                            <?php endif; ?>

                            <?php if ($this->countModules('search', true)) : ?>
                            <section id="search">
                                <jdoc:include type="modules" name="search" style="none" />
                            </section>
                            <?php endif; ?>

                            <jdoc:include type="modules" name="main-top" style="none" />
                            <jdoc:include type="message" />
                            <main>
                                <jdoc:include type="component" />
                            </main>

                            <jdoc:include type="modules" name="main-bottom" style="none" />

                        </div>
                    </div>

                    <?php if ($this->countModules('bottom-a', true)) : ?>
                    <jdoc:include type="modules" name="bottom-a" style="none" />
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </section>
    <?php endif; ?>

    <!-- Main --Sidebar left--->
    <?php if ($this->params->get('sidebarLeft')) : ?>
        <section id="main">
                <div class="container">
                    <div class="row">
                        <div class="col-3 col-12-medium">
                            <div class="sidebar">

                                <?php if ($this->countModules('sidebar-left', true)) : ?>
                                    <jdoc:include type="modules" name="sidebar-left" style="none" />
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="col-9 col-12-medium imp-medium">
                            <div class="content">
                                <?php if ($this->countModules('top-a', true)) : ?>
                                    <jdoc:include type="modules" name="top-a" style="hr" />
                                <?php endif; ?>

                                <?php if ($this->countModules('search', true)) : ?>
                                    <section id="search">
                                        <jdoc:include type="modules" name="breadcrumbs" style="none" />
                                    </section>
                                <?php endif; ?>

                                <?php if ($this->countModules('search', true)) : ?>
                                    <section id="search">
                                        <jdoc:include type="modules" name="search" style="none" />
                                    </section>
                                <?php endif; ?>

                                <jdoc:include type="modules" name="main-top" style="none" />
                                <jdoc:include type="message" />
                                <main>
                                    <jdoc:include type="component" />
                                </main>

                                <jdoc:include type="modules" name="main-bottom" style="none" />

                            </div>
                        </div>

                        <?php if ($this->countModules('bottom-a', true)) : ?>
                            <jdoc:include type="modules" name="bottom-a" style="none" />
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </section>
    <?php endif; ?>

    <!-- Main --Sidebar right--->
    <?php if ($this->params->get('sidebarRight')) : ?>
        <section id="main">
            <div class="container">
                <div class="row">
                    <div class="col-9 col-12-medium">
                        <div class="content">

                            <?php if ($this->countModules('top-a', true)) : ?>
                                <jdoc:include type="modules" name="top-a" style="hr" />
                            <?php endif; ?>

                            <?php if ($this->countModules('search', true)) : ?>
                                <section id="search">
                                    <jdoc:include type="modules" name="breadcrumbs" style="none" />
                                </section>
                            <?php endif; ?>

                            <?php if ($this->countModules('search', true)) : ?>
                                <section id="search">
                                    <jdoc:include type="modules" name="search" style="none" />
                                </section>
                            <?php endif; ?>

                            <jdoc:include type="modules" name="main-top" style="none" />
                            <jdoc:include type="message" />
                            <main>
                                <jdoc:include type="component" />
                            </main>
                            <jdoc:include type="modules" name="main-bottom" style="none" />
                        </div>
                    </div>

                    <?php if ($this->countModules('sidebar-right', true)) : ?>
                        <div class="col-3 col-12-medium">
                            <div class="sidebar">
                                <jdoc:include type="modules" name="sidebar-right" style="none" />
                            </div>
                        </div>
                    <?php endif; ?>
                    <?php if ($this->countModules('bottom-a', true)) : ?>
                        <jdoc:include type="modules" name="bottom-a" style="none" />
                    <?php endif; ?>
                </div>
            </div>
        </section>
    <?php endif; ?>

Man kann also nun die Darstellung ohne Sidebar, mit Sidebar auf der linken oder auf der rechten Seite steuern. Wichtig ist, dass von den drei Schaltern nur einer gesetzt ist. Eine Fehlerbehandlung ist (noch) nicht eingebaut.

Ich hätte nun doch noch zwei Fragen: Ich würde gern das Banner wählbar machen. Auf dem Reiter Tab habe ich ein entsprechendes Feld vom Typ media eingefügt und es lässt sich so mit dem Mediamanger ein Image auswählen. Bisher habe ich nicht die Stelle gefunden, wo das banner.jpg angezeigt wird. Diesen Aufruf würde ich gern mit dem entsprechenden Parameter ergänzen. Hast du dafür einen Tipp?

Um zu verhindern, dass man sowohl die rechte als auch die linke Sidebar anzeigt, würde ich in der index.php gern, in der if Abfrage für die linke Sidebar, den Parameter für die rechte Sidebar auf 0 - nicht gesetzt, setzen. Auch dazu wäre ein Tipp hilfreich. Jetzt fällt mir noch eine Frage ein :-) Wie stelle ich es an, eine Installationsfunktion nur für das Template zu bauen? Danke und LG phanti09

FilMar61 commented 1 year ago

When I click on Module - First steps I get a 404 (english version). Where can I find the article, please?

astridx commented 1 year ago

@FilMar61 You posted this in the table of contents. Please describe in more detail where you see the message 404.

FilMar61 commented 1 year ago

There, in the table of contents. When I choose the First part of the module, I get a 404, not the right article.

Greetings,

Filip

Op vr 7 okt. 2022 20:24 schreef Astrid @.***>:

@FilMar61 https://github.com/FilMar61 You posted this in the table of contents. Please describe in more detail where you see the message 404.

— Reply to this email directly, view it on GitHub https://github.com/astridx/meinblog/issues/18#issuecomment-1271922146, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQCDB3PTP4VLS2B5BLIGUBDWCBTFTANCNFSM5FBE2LAA . You are receiving this because you were mentioned.Message ID: @.***>

astridx commented 1 year ago

@FilMar61 Thank you very much. Now I understand correcly. I fixed the typo in the link of the table of content.

marcorensch commented 1 year ago

hi, i would like to purchase your book as pdf or epub but cannot find it anywhere online… can you give me a hint where i can buy it (in en or de)

keep up the good work 👍

astridx commented 1 year ago

@marcorensch I am pleased that you are interested in my text.

With the book, it is important to me that I can update it easily. With programming books, they quickly become outdated. I haven't found the right solution for me yet.

At the moment, you can find the latest German version as a PDF at https://astrid-guenther.de/images/banners/1.de.pdf and the ePub at https://astrid-guenther.de/images/banners/1.de.epub. For English version at https://astrid-guenther.de/images/banners/1.en.pdf and the ePub at https://astrid-guenther.de/images/banners/1.en.epub.

If you would like to support me, you can find opportunities in the footer of this blog (https://blog.astrid-guenther.de/).