8 – How do I display a field of parent memory in my module?

I own a Drupal 8.7 site with the Drupal Commerce 2.14 module.

I have created a marketplace (several merchants on the same site). In the business type, I created a field "Text (formatted, long)" with the computer name field_terms_and_conditions,

In this field, the trader specifies his general conditions of sale, which the customer must accept during the ordering process.

If the customer orders in multiple stores, multiple shopping carts are created (the name of the store is displayed above each cart). It works very well. Now that Drupal Commerce manages the address book, orders are very fast.

At the moment I have created a view that shows the content of the field field_terms_and_conditions on one side. I've also created a custom module to display a checkbox with a link to the general sales conditions in a modal window.

I want to render the field directly field_terms_and_conditions in the modal window without using a view. How do you do that ?

/src/Plugin/Commerce/CheckoutPane/MarketplaceTermsAndConditions.php :

order->getStore()->getName();
    $store_id = $this->order->getStoreId();
    $pane_form('#attached')('library')() = 'core/drupal.dialog.ajax';
    $attributes = (
      'attributes' => (
        'class' => 'use-ajax',
        'data-dialog-type' => 'modal',
        'data-dialog-options' => Json::encode((
          'width' => 'auto'
        )),
      ),
    );
    $link = Link::fromTextAndUrl(
      $this->t('terms and conditions of the store "@store_name"', ('@store_name' => $store_name)),
      Url::fromUri("internal:/store/$store_id/cgv", $attributes)
    )->toString();
    $pane_form('marketplace_terms_and_conditions') = (
      '#type' => 'checkbox',
      '#default_value' => FALSE,
      '#title' => $this->t('I have read and accept @terms.', ('@terms' => $link)),
      '#required' => TRUE,
      '#weight' => $this->getWeight(),
    );
    return $pane_form;
  }

}

Change states from child to parent while observing the SOLID principles

In artificial examples of some kind, it is often not clear whether or not they violate SOLID, and it is impossible to meaningfully rate the code as "good" or "bad". For example, the DIP says

"High-level modules should not depend on low-level modules, and both should depend on abstractions (such as interfaces)."

But what is "a high-level module" and what is "a low-level module" in this example? That's probably a matter of taste with a so invented car / driver example. You can see both the car and the driver together as "one module", or you can see each one of them as a module in their own right. For the latter case, it's easy to solve the mentioned DIP problem: just imagine another one IDriver Interface and make ICar depend on it Driver,

But is that "better"? Adding the interface makes the code a bit more complicated, and if that does not serve a purpose, it violates the KISS principle.

Another detail in your code is the weird-looking side effect in ExampleCar.Drive, Change the reference to a completely new car object within Drive looks inconspicuous to me – the "refueling" of the existing car would probably be more obvious, such as

 public void Drive(Driver owner){
    if(fuel > 0){
        fuel--;
        Console.Writeline("driving exampleCar. Fuel: " + fuel);
        return;
    }
    fuel=200;
    Console.Writeline("exampleCar refuled. Fuel: " + fuel);
 }

Perhaps this could be a violation of the "principle of least astonishment". If it is so Really A violation can only be evaluated in the context of a real application with real classes and real use cases. Perhaps there are reasons why the original side effect is necessary, and perhaps the effect in the "real" context may not look as unexpected to a user of those classes.

In short, there are more programming principles than just SOLID. Their application often requires compromises, and artificial examples usually lack sufficient context to rate them as "good" or "bad" in design.

Command line – Delete empty subfolders, keep the parent folder

When I use

find /home/user/parentdir -type d -empty -delete

It recursively searches for empty subfolders in / home / user / parentdir and deletes them. However, if / home / user / parentdir is also empty, the parent folder is deleted, which is undesirable to me.

I keep this parent directory to sync some files to the backup or the cloud. After the process, I have to delete empty folders, but it seems unproductive to recreate them each time.

Any suggestions to keep parentdir? I've been thinking about creating a ".nocopy" file in parentdir and excluding it from rsync, but it looks like overkill. Is there a more elegant way?

mysql – selects rows and calculates the number of rows based on the value of the parent column

I have a total of three tables with a many to many relationship.

1.] Users

id | email
-----------
1  | usera@example.com
2  | userb@example.com
3  | userc@example.com

2.] Accounts

id | userId | availableBalance | currencyCode
1  | 1      | 30               | USD
2  | 2      | 12               | USD
3  | 3      | 0                | USD

3.] Transactions

id | accountId | toId | amount | currencyCode | pending
1  | 2         | 1    | 6      | USD          | true
2  | 2         | 3    | 6      | USD          | true
3  | 2         | 1    | 6      | USD          | true

B has an account and his balance is $ 12. It creates three transactions 1, 2 and 3 for users A, C and A.

  1. I want to check how many transactions can be completed successfully.
  2. If user b has only $ 6 and he has created two transactions, one for user a and one for user b with the same amount of $ 6. Then, as User A, I want to count that kind of transaction so he can get money or not.

SQL Server – Create and update a parent SQL column with values ​​extracted from the same table

I have a table named Name and Name. I need to add the new Parent column to the table and include the generic values. NameId is currently the PK.

table

Enter image description here

I have created a temporary table that contains the parent values. Could not figure out how to update the "parent" column values. Please give advice on what I can do to achieve this.

Thank you very much

Design Pattern – Preferred way to interact with parent and child components at an angle

I'm writing a web app in Angular 8.
There is a logic where a child component must interact with the parent component and vice versa.

Below is a diagram. I implemented the first approach, but I was wondering if it would be better to implement the second approach.

Code from my service

export class ScoreService {

  constructor() { }

  private matchWinnerSource = new Subject();

  // Child component is subscribed to this observable
  matchWinner = this.matchWinnerSource.asObservable();

  // Parent component calls this method
  setMatchWinner(winnerId: number, winnerStringRepresentation: string, matchId: number) {
    const data = {
      id: winnerId,
      winnerStringRepresentation,
      matchId
    }
    this.matchWinnerSource.next(data);
  }
}

Enter image description here

Note: Not sure if Desgin Patterns is an appropriate day here.

Export data from DHIS2 with link between parent and child tables?

We try to export a "parent table" with their "child table", if we can call it that.
Both are linked by a relationship type. When data is added to the parent table, the user can switch to the Relationship tab and add more data, which works very well.

The problem is with the export. The data is exported separately without linking or linking between them. We use an online server for DHIS2, so we do not have direct access to the database structure.

If this issue is resolved, we can use DHIS2 to reach the final implementation level. And the connection between these two tables is sensitive.

How can data from both tables be exported with a join / key connection between both tables?

dhis2 – Parent and child tables are exported without a join key, although there is a relationship.

We try to export a "parent table" with their "child table", if we can call them that.
Both are linked by a relationship type. When data is added to the parent table, the user can switch to the Relationship tab and add more data, which works very well.

The main problem is the export. The data is exported separately without linking or linking between them. We use an online server for DHIS2, so we do not have direct access to the database structure.

If this problem is resolved, we are ready to use DHIS2 for the final phase of the implementation. And the connection between these two tables is sensitive.

How can data from both tables be exported with a join / key connection between both tables?

8 – How can I get the parent node of a referenced node?

I think HostEntity was specific to FieldCollection in D7 and not to entity references. The field collection is bound to a specific host entity. There is no specific host entity with the entity reference. You may be able to reference an entity in multiple host entities.

With the entity query, you can retrieve all (host) nodes that point to a specific entity in a particular field.

In a very simple form, this would return all "project" nodes pointing to a particular building field by field:

$query = Drupal::entityQuery('node')
  ->condition('field_building', $building_nid);
$nids = $query->execute();

$ building_nid is the node ID of the building. This will return "project" node IDs in your case.

entity – How do I get the data of the parent node (host entity) of a node in Drupal 8?

I have a node named Project that contains the Build field as a referenced item. I used the hook when inserting the building node and with this building ID I have to get the project ID assigned to this building. How can I retrieve the project ID (the parent of the building)?

I found the hostEntity () used in Drupal 7 (as far as I know), but it seemed that this was no longer true in Drupal 8.

Appreciate your help!